#P10593. BZOJ2958 序列染色

BZOJ2958 序列染色

Background

This problem comes from the original BZOJ. We acknowledge that the copyright of the statement and the original testdata belongs to the original BZOJ or to the problem author(s) who authorized BZOJ to use it. If you are the copyright holder and believe that we have infringed your rights, please contact us.

Problem Description

You are given a string SS of length nn consisting of the three characters B, W, and X. You need to recolor each X into either B or W.

For the given kk, ask how many coloring methods make it possible that there exist integers a,b,c,da, b, c, d satisfying:

  • 1ab<cdn1 \le a \le b < c \le d \le n;
  • b=a+k1b = a + k - 1, d=c+k1d = c + k - 1;
  • Sa=Sa+1==Sb=BS_a = S_{a+1} = \dots = S_b = \tt B;
  • Sc=Sc+1==Sd=WS_c = S_{c+1} = \dots = S_d = \tt W.

Since the number of methods may be large, you only need to output the final answer modulo 109+710^9 + 7.

Input Format

The first line contains two positive integers n,kn, k.

The second line contains a string SS of length nn.

Output Format

Output one line containing one integer, representing the answer.

5 2
XXXXX
4

Hint

For 20%20\% of the testdata, 1n201 \le n \le 20.

For 50%50\% of the testdata, 1n20001 \le n \le 2000.

For 100%100\% of the testdata, 1n,k1061 \le n, k \le 10^6.

Translated by ChatGPT 5