#P8256. [NOI Online 2022 入门组] 字符串
[NOI Online 2022 入门组] 字符串
Background
After consideration by the administrators, we plan to store the unofficial testdata separately in the last Subtask. These test points all have a score of 0, but failing to pass any of them will be considered as not passing this problem.
In this problem, there was an issue where the test point numbers in the judging records were in a mess. This was caused by a naming conflict in the unofficial testdata. However, we guarantee that their relative order is not mixed up.
Unofficial testdata provider: @tiger2005.
Problem Description
Kri really likes strings, so he prepares to study groups of strings.
In the -th study, Kri prepares two strings and . Here, has length and consists only of the three characters 0, 1, and - (note: the third character is a minus sign). Initially, is empty.
In each study, Zay comes to play with Kri, bringing a beautiful string of length . Kri is very envious that Zay has such a beautiful string, so he also wants to use strings and to produce string .
Specifically, Kri will perform operations. In each operation, Kri takes the first character of (denoted as ) and deletes it from . If , then Kri must delete the first character or the last character of (the testdata guarantees that after deletion, is not empty). Otherwise, Kri appends to the end of .
After all operations are finished, Kri checks whether is equal to . If , Kri will feel happy; otherwise, Kri will feel sad.
For each study, how many different ways of operating will make Kri happy in the end? We define two plans as different if and only if, in some operation of some plan, Kri deletes the first character of , while in the corresponding operation of the other plan, Kri deletes the last character of .
Since the answer may be very large, you only need to output the remainder of the answer modulo (i.e. ).
Input Format
The first line contains a positive integer .
Then there are test cases, representing studies of strings. For each test case:
The first line contains two positive integers , representing the lengths of strings and .
The second line is the string .
The third line is the string .
Output Format
Output lines in total. The -th line denotes the answer for the -th test case.
3
6 2
10-01-
01
7 3
010-1-1
101
6 4
111-00
1100
2
1
2
见附件中的 string2.in
见附件中的 string2.out
Hint
[Sample 1 Explanation]
For the first test case, there are two plans as follows:
- The first
-deletes the first character of , and the second-deletes the first character of . - The first
-deletes the last character of , and the second-deletes the first character of .
[Constraints]
For of the testdata, .
For of the testdata, .
For of the testdata, .
For the other of the testdata, it is guaranteed that the answer does not exceed .
For of the testdata, , .
Translated by ChatGPT 5