#P5362. [SDOI2019] 连续子序列
[SDOI2019] 连续子序列
Description
We define the sequence as a Boolean sequence of the following form:
- .
- .
- .
Here are the first several terms of the sequence: .
The sequence is an infinite sequence, and it has many consecutive subsequences.
For example, , , , , and are all consecutive subsequences of it, while and are not.
Now you are given a Boolean sequence (a 01 string) and a non-negative integer . Please count how many different consecutive subsequences of the sequence satisfy:
- is a prefix of .
- is formed by appending exactly more terms to the right of .
Input Format
The first line contains an integer , indicating that there are test cases.
Then follow lines. Each line contains a 01 string (representing a Boolean sequence) and a non-negative integer , describing one test case.
Output Format
For each test case, output one line containing an integer, indicating the number of consecutive subsequences that satisfy the conditions. Since the value may be very large, output it modulo .
5
1001 3
11001 10
00111 10
0011 20
0 100
3
4
0
6
164
Hint
Subtask ( points): , the length of the given Boolean sequence is at most , and .
Subtask ( points): , the length of the given Boolean sequence is at most , and .
Subtask ( points): , the length of the given Boolean sequence is at most , and .
Translated by ChatGPT 5
京公网安备 11011102002149号