Moo Decomposition
시간 제한: 2000ms메모리 제한: 2048MB출처: USACO 2025 Open GoldBOJ 33763
문제
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 .
입력
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 the number of decompositions of string , modulo .
예제
예제 1
입력
2 6 1 MOOMOO
출력
1
예제 2
입력
2 6 1 MMOOOO
출력
6
예제 3
입력
1 4 2 MMOO
출력
4
예제 4
입력
1 4 100 MMOO
출력
976371285
코드를 제출하려면 로그인하세요.