#P10593. Coloring to Form Valid Contiguous Runs
Coloring to Form Valid Contiguous Runs
Coloring to Form Valid Contiguous Runs
You are given a string S of length n consisting of the characters B
, W
and X
. For every occurrence of X
you can independently change it to either B
or W
. You are also given an integer k.
Your task is to count the number of ways to recolor all the X
characters such that there exist four integers a, b, c, d satisfying
with
and such that
Output the answer modulo \(10^9+7\).
Note: The two contiguous segments must be non‐overlapping, and the segment of B
's must entirely come before the segment of W
's.
inputFormat
The first line contains two integers n
and k
(the length of the string and the length of each desired segment, respectively).
The second line contains the string S
of length n
, consisting of the characters B
, W
and X
.
outputFormat
Output a single integer: the number of valid colorings that satisfy the condition, modulo \(10^9+7\).
sample
5 2
BXXWW
2