String Game
Time limit2sMemory limit256 MB
Count the distinct binary strings of length k reachable from a given string by deleting 000 or 11 or swapping adjacent unequal characters.
- Level
Medium7 of 10
- Topics
- Dynamic programming, Combinatorics, String, Math
- Solved
- No attempts yet
Problem
Grisha and Dima are playing a game again. This time they have a string of zeros and ones. The following operations can be performed on the string:
- delete three consecutive ones;
- delete two consecutive zeros;
- replace the substring "
01" with the substring "10"; - replace the substring "
10" with the substring "01".
For example, in one operation the string "00111" can become the strings "00", "111", and "01011".
Now the boys are interested in the following question: how many distinct strings of length can be obtained from the given string using the described operations. Grisha and Dima are busy with their exams, so they ask you to help them.
Given a string and a number , determine how many distinct strings of length can be obtained from the given string using the described operations.
Input
The first line contains a positive integer (), the number of test cases in the input. The descriptions of the test cases follow.
Each test case is described by two lines. The first line contains two positive integers and (), the length of the original string and the length of the string to be obtained. The second line contains a string of length consisting of zeros and ones.
Output
Output lines. For each test case, output the number of strings of length that can be obtained from the given string using the described operations. Since the answer can be quite large, output it modulo .