#P7969. [KSN2021] Self Defence

[KSN2021] Self Defence

Problem Description

Define the weight of a string as the number of its substrings that have length MM and contain only one distinct character.

For example, for the string ABBB, when M=2M=2, its weight is 22.

Given a string of length NN, where each character is one of ?, A, and B, you need to find how many strings can be obtained with weight KK after replacing each ? with A or B.

Output the answer modulo 109+710^9+7.

Input Format

The first line contains three integers N,M,KN,M,K.

The second line contains a string SS of length NN.

Output Format

Output one integer representing the answer.

5 4 1
?????
4
5 2 2
A????
6
5 3 4
AAAAA
0

Hint

Sample Explanation

For the first sample, the following are all valid strings:

AAAAB
ABBBB
BAAAA
BBBBA

For the second sample, the following are all valid strings:

AAABA
AABAA
AABBA
ABAAA
ABBAA
ABBBA

Constraints

This problem uses bundled testdata.

  • Subtask 1 (5 points): There is only one test case, satisfying N=10N=10, M=3M=3, K=5K=5, S=????A???B?S=\texttt{????A???B?}.
  • Subtask 2 (9 points): N20N\le 20.
  • Subtask 3 (11 points): N200N\le 200.
  • Subtask 4 (6 points): M=2M=2, K=0K=0.
  • Subtask 5 (9 points): K=0K=0.
  • Subtask 6 (8 points): K1K\le 1.
  • Subtask 7 (27 points): SS contains only ?.
  • Subtask 8 (25 points): No special restrictions.

For all test cases, 1N30001\leq N\leq 3000, 1MN1\leq M\leq N, 0KN0\leq K\leq N.

Translated by ChatGPT 5