#P10310. 「Cfz Round 2」01 String
「Cfz Round 2」01 String
Problem Description
A string is defined as valid if and only if its first character is and its last character is . We further define the weight of a string as the number of ways to split into several consecutive valid substrings.
For example, , because it can only be split as ; , because it can be split in four different ways: ; while .
Given a string of length . Define $f_k(l, r) = \begin{cases} f(S_{l\dots r}) & k = 0 \\ \displaystyle\sum_{l\leq l' \leq r' \leq r} f_{k-1}(l', r') & k \gt 0\end{cases}$. You need to compute the value of .
Since the answer may be very large, you only need to output it modulo .
Input Format
This problem contains multiple test cases.
The first line contains an integer , denoting the number of test cases.
Then the test cases follow. For each test case:
- The first line contains two integers , representing and the given parameter.
- The next line contains a string of length , representing .
Output Format
For each test case, output one line with one integer, representing the answer.
4
3 1
001
5 2
00101
30 10
010100110101001010010010011101
10 1000000000000
0010110101
2
19
926292963
340558843
Hint
"Sample Explanation #1"
For the first test case, use the intersections in the tables to represent the values of :
| / | |||
| / |
| / | |||
| / |
Where:
- $f_1(2, 3)= f_0(2, 2) + f_0(2, 3) + f_0(3, 3)= 0 + 1 + 0 = 1$.
- $f_1(1, 3) = f_0(1, 1) + f_0(1, 2) + f_0(1, 3) + f_0(2, 2) + f_0(2, 3) + f_0(3, 3) = 0 + 0 + 1 + 0 + 1 + 0 = 2$.
So the answer is .
Constraints
Let denote the sum of within a single test file.
For all testdata, , , , , and it is guaranteed that contains only and .
Only if you pass all test points of this problem can you obtain the score for this problem.
Translated by ChatGPT 5