Separate String
Time limit2sMemory limit512 MB
Count the ways to split string t into a sequence of pieces, each of which is one of N given dictionary strings, modulo 1e9+7.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Trie, String matching, String
- Solved
- No attempts yet
Problem
You are given a string and a set of distinct strings. You must split into pieces so that every piece is an element of .
For example, when = abab and = {a, ab, b}, the following 4 splittings satisfy the condition.
a,b,a,ba,b,abab,a,bab,ab
Count the number of ways to split . The answer can be very large, so print the remainder after dividing it by 1,000,000,007.
Input
The input consists of a single test case in the following format.
N
s1
.
.
.
sN
t
The first line contains an integer (), the number of elements of . The next lines contain distinct strings, one per line. The -th string is the -th element of . Each consists of lowercase letters and has length between 1 and 100,000, inclusive. The sum of the lengths of all () is at most 200,000. The last line contains the string to be split. consists of lowercase letters and has length between 1 and 100,000, inclusive.
Output
Print the number of ways to split , modulo 1,000,000,007.