#P6482. [CRCI2006-2007] CIRCLE
[CRCI2006-2007] CIRCLE
Problem Description
You are given a ring (circular arrangement) of pebbles. There are pebbles in total, and each pebble is either black or white.
Mirko will perform operations on this ring of pebbles. This ring is called the initial sequence. One operation is defined as follows:
-
If two adjacent pebbles have the same color, insert a black pebble between them.
-
If two adjacent pebbles have different colors, insert a white pebble between them.
-
Repeat the above steps times.
-
Here, adjacency is considered only among the original pebbles. The pebbles inserted later are not counted.
-
In the end, the original ring of pebbles will increase to pebbles. Remove the initial sequence; the remaining pebbles (i.e., the newly inserted pebbles) are the result after one operation.
Given an initial sequence, after operations you will obtain a result. You need to find: how many different initial sequences can also produce the same result after operations?
Input Format
The first line contains two integers .
The second line contains characters describing the colors of the pebbles. W means white, and B means black.
Output Format
Output one integer in one line, representing the number of different initial sequences. (The given one in the input should be included in the answer.)
3 1
BBW
2
6 2
WBWWBW
3
Hint
Sample 1 Explanation
The sequences BBW and WBW both become BWW after operation. Therefore, there are possible initial sequences.
Constraints
For of the testdata, and .
Note
Translated from COCI2006-2007 Regional Competition T4 CIRCLE。
Translated by ChatGPT 5