#P4591. [TJOI2018] 碱基序列
[TJOI2018] 碱基序列
Description
Xiaodou joined a biology laboratory. In the lab, he mainly studies proteins. The protein he is currently studying consists of amino acids in a fixed order. For each amino acid , there are possible base sequences .
Now Xiaodou has a base string , and he wants to know how many different combinations could produce this protein on this base string. That is, consider the string obtained by concatenating string segments in order, where for the -th segment you choose one sequence from its options. Count how many different ways can match the string as a contiguous substring. Two ways are considered different if either the choices for the segments differ, or the matched positions in differ.
Input Format
- The first line contains an integer indicating that the protein consists of amino acids.
- The second line contains a string , which is the current base string.
- The next lines describe the possible base sequences for the -th amino acid. For the -th amino acid, the line starts with , the number of possible base sequences, followed by strings representing these possible base sequences, separated by spaces.
Output Format
Output a single integer: the number of different ways (either different substrings of , or for the same substring, different choices of sequences for the amino acids). The answer is taken modulo .
2
ABC
2 A AB
2 C BC
2
2
AAA
2 A AA
2 A AA
4
Hint
Sample 1 Explanation
- First choose , second choose , obtaining , which matches in ways.
- First choose , second choose , obtaining , which matches in way.
- First choose , second choose , obtaining , which matches in way.
- First choose , second choose , obtaining , which matches in ways.
Therefore there are ways in total.
Sample 2 Explanation
- First choose , second choose , obtaining , which matches in ways.
- First choose , second choose , obtaining , which matches in way.
- First choose , second choose , obtaining , which matches in way.
- First choose , second choose , obtaining , which matches in ways.
Therefore there are ways in total.
Constraints
- For of the testdata, , , .
- For of the testdata, , , . The length of each base sequence does not exceed . The character set consists of uppercase letters.
Translated by ChatGPT 5
京公网安备 11011102002149号