#P16812. [蓝桥杯 2026 国 Python A] 压缩字符串
[蓝桥杯 2026 国 Python A] 压缩字符串
Problem Description
Given a string of length , the string consists only of the characters , , and .
You may perform the “compress” operation on string any number of times (including times). One compress operation is defined as follows: choose two adjacent characters in the string, and both of them are not . Delete either one of them. The remaining characters will automatically be concatenated together.
Now a target length is given. Please compute: after performing some operations, how many different strings of length exactly can be obtained in the end. Since the answer may be very large, output the number of ways modulo .
Input Format
The first line contains two integers and , representing the initial length of the string and the target length.
The second line contains a string of length consisting only of , , and .
Output Format
Output one integer, the number of different strings that can be obtained modulo .
6 4
010#11
5
Hint
Sample Explanation
The different strings that can be obtained are:
- 00#1
- 01#1
- 10#1
- 0#11
- 1#11
There are kinds in total.
Constraints
For of the testdata, , and the number of characters in does not exceed .
For all testdata, , , and , and the number of characters in does not exceed .
Translated by ChatGPT 5