#P12028. [USACO25OPEN] Moo Decomposition G
[USACO25OPEN] Moo Decomposition G
Description
You have a long string of Ms and Os and an integer . Count the number of ways of ways to decompose into subsequences such that each subsequence is MOOOO....O with exactly Os, modulo .
Since the string is very long, you are not given it explicitly. Instead, you are given an integer (), and a string of length (). The string is the concatenation of copies of the string .
Input Format
The first line contains , , and .
The second line contains the string of length . Every character is either an M or an O.
It is guaranteed that the number of decompositions of is nonzero.
Output Format
Output the number of decompositions of string , modulo .
2 6 1
MOOMOO
1
2 6 1
MMOOOO
6
1 4 2
MMOO
4
1 4 100
MMOO
976371285
Hint
For Sample 1:
The only way to decompose into MOOs is to let the first three characters form a MOO and the last three characters form another MOO.
For Sample 2:
There are six distinct ways to decompose the string into subsequences (uppercase letters form one MOO, lowercase letters form another):
- MmOOoo
- MmOoOo
- MmOooO
- MmoOOo
- MmoOoO
- MmooOO
For Sample 4:
Make sure to take the answer modulo .
SCORING:
- Inputs 5-7: ,
- Inputs 8-10: , ,
- Inputs 11-13:
- Inputs 14-19:
- Inputs 20-25: No additional constraints.
京公网安备 11011102002149号