Orig Description
Score : 1100 points
Problem StatementThere are N white balls arranged in a row, numbered 1,2,..,N from left to right.
AtCoDeer the deer is thinking of painting some of these balls red and blue, while leaving some of them white.
You are given a string s of length K.
AtCoDeer performs the following operation for each i from 1 through K in order:
The i-th operation: Choose a contiguous segment of balls (possibly empty), and paint these balls red if the i-th character in s is r; paint them blue if the character is b.
Here, if a ball which is already painted is again painted, the color of the ball will be overwritten.
However, due to the properties of dyes, it is not possible to paint a white, unpainted ball directly in blue.
That is, when the i-th character in s is b, the chosen segment must not contain a white ball.
After all the operations, how many different sequences of colors of the balls are possible?
Since the count can be large, find it modulo 10^9+7.
Constraints
1 ≤ N ≤ 70
1 ≤ K ≤ 70
|s| = K
s consists of r and b.
N and K are integers.
InputInput is given from Standard Input in the following format:
N K
s
OutputPrint the number of the different possible sequences of colors of the balls after all the operations, modulo 10^9+7.
Sample Input 12 2
rb
Sample Output 19
There are nine possible sequences of colors of the balls, as follows:
ww, wr, rw, rr, wb, bw, bb, rb, br.
Here, r represents red, b represents blue and wrepresents white.
Sample Input 25 2
br
Sample Output 216
Since we cannot directly paint white balls in blue, we can only choose an empty segment in the first operation.
Sample Input 37 4
rbrb
Sample Output 31569
Sample Input 470 70
bbrbrrbbrrbbbbrbbrbrrbbrrbbrbrrbrbrbbbbrbbrbrrbbrrbbbbrbbrbrrbbrrbbbbr
Sample Output 4841634130
Extracted Specification
An integer N (1 ≤ N ≤ 70), representing some quantity or size.
An integer K (1 ≤ K ≤ 70), representing some quantity or size.
A string s of length K, consisting of characters from the set {'r', 'b'}.
### Example Input:
```
12 2
rb
```
### Function Signature:
Write a function f(N, K, s) that takes in the input.
def f(N: int, K: int, s: str):
'''
N: an integer
K: an integer
s: a string
'''
Test Case Generator
Sure! To generate test cases for the given problem statement, we need to carefully construct the test cases such that they follow the constraints and edge cases specified in the problem. Here's a Python function to generate test cases for this problem:
```python
import random
def tcgen():
# Constraints
N = random.randint(1, 70)
K = random.randint(1, 70)
s = ''.join(random.choice(['r', 'b']) for _ in range(K))
return N, K, s
def format_test_case(N, K, s):
return f"{N} {K}\n{s}"
# Example usage
if __name__ == "__main__":
for _ in range(5): # Generate 5 test cases
N, K, s = tcgen()
test_case = format_test_case(N, K, s)
print(test_case)
print()
```
### Explanation:
1. **Constraints:**
- Generate \(N\) between 1 and 70.
- Generate \(K\) between 1 and 70.
- Create a string \(s\) of length \(K\), consisting of 'r' and 'b' characters.
2. **Random Generation:**
- Use `random.randint` to generate random values for \(N\) and \(K\) within their respective ranges.
- Use `random.choice` to randomly select characters 'r' or 'b' to form the string \(s\).
3. **Formatting:**
- The `format_test_case` function formats the test case in the required input format.
4. **Example Usage:**
- Generate and print 5 test cases as examples.
This test case generator will create random test cases within the problem's constraints, ensuring a variety of inputs for robust testing.
Extract Arguments
def extract_arguments(fh):
N, K = map(int, fh.readline().strip().split())
s = fh.readline().strip()
return N, K, s