Illuminated Lights II
InterviewTime limit1sMemory limit1024 MB
Count the subsets of lights, each pointing L or R, that illuminate every light in the row, modulo 1e9+7.
- Level
Medium5 of 10
- Topics
- Dynamic programming, String
- Solved
- No attempts yet
Statement
There are lights in a row, all initially deactivated. Some lights, when activated, illuminate themselves and all lights to their left. The others, when activated, illuminate themselves and all lights to their right.
The image below shows the result of activating only the fourth light in the first sample case. Lights 1 through 4 are illuminated, and no others are.

You already know the minimum number of lights that must be activated to illuminate everything, from this earlier problem. Now you want to count the good subsets.
A subset of the lights is good if activating only the lights in illuminates every light in the row. Count the good subsets. Since the count can be large, print it modulo .
Input
The first line contains a single integer (), the number of test cases. Each test case starts with a line containing a single integer (), the number of lights. The next line contains a string of length made of the characters L and R. L means the light points left, and R means it points right.
The sum of over all test cases does not exceed .
Output
For each test case, print the number of good subsets modulo on its own line.
Hint
For the second and fourth test cases, the only way to illuminate everything is to activate every light. So for these cases, the only good subset is the set of all lights.
For the third test case, activating either light illuminates everything. So the sets , , and are good.