Hiring process8 levels
  1. 1 IQ Test
  2. 2 Additional Online Test (If Required)
  3. 3 Office Interview with Hiring Manager
  4. 4 Unpaid Test Task (Motivation Check)
  5. 5 Paid Test Task and Follow-Up Interview
  6. 6 Iterative Paid Test Tasks
  7. 7 Office Verification
  8. 8 Final Interview with the Founder

Problems > Sentence Reconstructions

Sentence Reconstructions

Difficulty: 1700 5000 ms 128 MB

strings dp

Given a dictionary and a text, count the ways to split the text into a sequence of dictionary words, modulo 109+7.

Input: the first line has D (dictionary size); the next D lines are the distinct words; the following line is the text.

Output: the number of segmentations mod 109+7.

Constraints:

  • 1 ≤ D ≤ 1000
  • 1 ≤ total word length ≤ 105
  • 1 ≤ |text| ≤ 105

Sample Tests

Input 1
2
ab
c
abc
Output 1
1
Input 2
1
xy
xyz
Output 2
0

Read the Editorial Statistics

Discussion (opens after you solve — no spoilers before)

No comments yet.

Submit Your Solution

Log in or create a free account to run and submit code.
Ctrl+Enter submit · Ctrl+Space autocomplete · F11 fullscreen