#P16812. [蓝桥杯 2026 国 Python A] 压缩字符串

    ID: 19153 远端评测题 3000ms 512MiB 尝试: 0 已通过: 0 显示难度提高 上传者: 标签>动态规划 DP2026蓝桥杯国赛

[蓝桥杯 2026 国 Python A] 压缩字符串

Problem Description

Given a string SS of length NN, the string consists only of the characters 00, 11, and #\#.

You may perform the “compress” operation on string SS any number of times (including 00 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 KK is given. Please compute: after performing some operations, how many different strings of length exactly KK can be obtained in the end. Since the answer may be very large, output the number of ways modulo 998244353998244353.

Input Format

The first line contains two integers NN and KK, representing the initial length of the string and the target length.

The second line contains a string SS of length NN consisting only of 00, 11, and #\#.

Output Format

Output one integer, the number of different strings that can be obtained modulo 998244353998244353.

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 55 kinds in total.

Constraints

For 20%20\% of the testdata, 1N2001 \le N \le 200, and the number of #\# characters in SS does not exceed 11.

For all testdata, 1N1051 \le N \le 10^5, 1K20261 \le K \le 2026, and KNK \le N, and the number of #\# characters in SS does not exceed 100100.

Translated by ChatGPT 5