#P10310. 「Cfz Round 2」01 String

    ID: 10885 远端评测题 1000ms 512MiB 尝试: 0 已通过: 0 难度: 7 上传者: 标签>数学洛谷原创O2优化组合数学洛谷月赛

「Cfz Round 2」01 String

Problem Description

A 01\tt{01} string is defined as valid if and only if its first character is 0\tt 0 and its last character is 1\tt 1. We further define the weight f(T)f(T) of a 01\tt{01} string TT as the number of ways to split TT into several consecutive valid substrings.

For example, f(001)=1f(\tt{001}) = \text{1}, because it can only be split as [001][\tt 001]; f(0101101)=4f(\tt{0101101}) = \text{4}, because it can be split in four different ways: [0101101][01,01101][01011,01][01,011,01][\tt 0101101][01, 01101][01011, 01][01, 011, 01]; while f(1001010101)=0f(\tt{1001010101}) = \text{0}.

Given a 01\tt{01} string SS of length nn. 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 fk(1,n)f_k(1, n).

Since the answer may be very large, you only need to output it modulo 109+710^9+7.

Input Format

This problem contains multiple test cases.

The first line contains an integer TT, denoting the number of test cases.

Then the test cases follow. For each test case:

  • The first line contains two integers n,kn, k, representing S\lvert S\rvert and the given parameter.
  • The next line contains a 01\tt{01} string of length nn, representing SS.

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 fk(l,r)f_k(l, r):

k=0\bm{k = 0} r=1r = 1 22 33
l=1l = 1 00 00 11
22 /
33 / 00
k=1\bm{k = 1} r=1r = 1 22 33
l=1l = 1 00 00 22
22 / 11
33 / 00

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 22.

Constraints

Let n\sum n denote the sum of nn within a single test file.

For all testdata, 1T1001 \leq T \leq 100, 1n2×1051 \leq n \leq 2\times 10^5, 0k10180 \leq k \leq 10^{18}, n6×105\sum n \leq 6\times 10^5, and it is guaranteed that SS contains only 0\tt{0} and 1\tt{1}.

Only if you pass all test points of this problem can you obtain the score for this problem.

Translated by ChatGPT 5