Illuminated Lights II

시간 제한1초메모리 제한1024 MB

요약
각 전등이 왼쪽 또는 오른쪽 한 방향만 비출 때, 활성화한 전등이 모든 전등을 밝히는 부분집합의 개수를 10^9+7로 나눈 나머지로 구한다.
난이도

어려움10점 중 8점

유형
조합론, 동적 계획법, 그리디, 누적 합
정답자
아직 제출이 없습니다

문제

There are nn lights in a row, all initially deactivated. Some lights, when activated, will illuminate themselves and all lights to their left. The others, when activated, will illuminate themselves and all lights to their right.

This image shows the result of activating the fourth light (and nothing else) in the first sample case. The first four lights are illuminated, and everything else is not.

You have already figured out the minimum number of lights that need to be activated to illuminate everything, but now, you're wondering how many good subsets of lights exist.

A subset SS of the lights is considered good if when you activate the lights in SS (and only the lights in SS), every light on the row is illuminated.

How many good subsets are there? Since the answer may be large, output it modulo 109+710^9+7.

입력

The first line of the input contains a single integer tt (1≤t≤1041 \le t \le 10^4) --- the number of test cases. The description of the test cases follows.

The first line of each test case contains a single integer nn (1≤n≤2⋅1051 \le n \le 2\cdot 10^5) --- the number of lights.

The next line of each test case contains a string ss consisting of nn characters L and R, indicating whether the lights are pointed to the left or right.

It is guaranteed that the sum of nn over all test cases does not exceed 2⋅1052\cdot 10^5.

출력

For each test case, print a single integer --- the number of good subsets, taken modulo 109+710^9+7.

힌트

For the second and fourth test cases, the only way to illuminate everything is to activate every light. Therefore, for these cases, the only good subset is the set containing all lights.

For the third test case, as long as either of the two lights is activated, everything will be illuminated. Therefore, the sets 1\\{1\\}, 2\\{2\\}, and 1,2\\{1, 2\\} are good.

예제1

  1. 예제 1

    입력
    7
    6
    LRRLRL
    1
    L
    2
    RL
    2
    LR
    5
    RRRRL
    10
    LRLRLRLRLR
    31
    LLLLLLLLLLLLLLLLLLLLLLLLLLLLLLL
    
    예상 출력
    50
    1
    3
    1
    24
    912
    73741817