#533
Unrated
Routing Schemes
시간 제한
2s
메모리 제한
1024MB
제출
0
정답
0
맞힌 사람
0
정답 비율
0.0%

문제

Consider a network of NN (2N1002\le N\le 100) nodes labeled 1N1\ldots N. Each node is designated as a sender, a receiver, or neither. The number of senders, SS, is equal to the number of receivers (S1S\ge 1).

The connections between the nodes in this network can be described by a list of directed edges each of the form iji\to j, meaning that node ii may route to node jj. Interestingly, all of these edges satisfy the property that i<ji<j, aside from KK that satisfy i>ji>j (0K20\le K\le 2). There are no self-loops (edges of the form iii\to i).

The description of a "routing scheme" consists of a set of SS directed paths from senders to receivers such that no two of these paths share an endpoint. That is, the paths connect distinct senders to distinct receivers. A path from a sender ss to a receiver rr can be described as a sequence of nodes s=v0v1v2ve=rs=v_0\to v_1 \to v_2\to \cdots \to v_e=r such that the directed edges vivi+1v_i\to v_{i+1} exist for all 0i<e0\le i<e. A node may appear more than once within the same path.

Count the number of distinct routing schemes such that every directed edge is traversed exactly once. Since the answer may be very large, report it modulo 109+710^9+7. It is guaranteed that there is at least one routing scheme satisfying these constraints.

Each input contains TT (1T201\le T\le 20) test cases that should be solved independently. It is guaranteed that the sum of N2N^2 over all test cases does not exceed 21042\cdot 10^4.

입력

The first line of the input contains TT, the number of test cases.

The first line of each test case contains the integers NN and KK. Note that SS is not explicitly given within the input.

The second line of each test case contains a string of length NN. The ii-th character of the string is equal to S if the ii-th node is a sender, R if the ii-th node is a receiver, or . if the ii-th node is neither. The number of Rs in this string is equal to the number of Ss, and there is at least one S.

The next NN lines of each test case each contain a bit string of NN zeros and ones. The jj-th bit of the ii-th line is equal to 11 if there exists a directed edge from node ii to node jj, and 00 otherwise. As there are no self-loops, the main diagonal of the matrix consists solely of zeros. Furthermore, there are exactly KK ones below the main diagonal.

Consecutive test cases are separated by newlines for readability.

출력

For each test case, the number of routing schemes such that every edge is traversed exactly once, modulo 109+710^9+7. It is guaranteed that there is at least one valid routing scheme for each test case.

예제 입력 1

2

8 0
SS....RR
00100000
00100000
00011000
00000100
00000100
00000011
00000000
00000000

13 0
SSS.RRRSS.RR.
0001000000000
0001000000000
0001000000000
0000111000000
0000000000000
0000000000000
0000000000000
0000000001000
0000000001000
0000000000110
0000000000000
0000000000000
0000000000000

예제 출력 1

4
12

예제 입력 2

2

5 1
SS.RR
00101
00100
10010
00000
00000

6 2
S....R
001000
000100
010001
000010
001000
000000

예제 출력 2

3
1

예제 입력 3

5

3 2
RS.
010
101
100

4 2
.R.S
0100
0010
1000
0100

4 2
.SR.
0000
0011
0100
0010

5 2
.SSRR
01000
10101
01010
00000
00000

6 2
SS..RR
001010
000010
000010
000010
100101
000000

예제 출력 3

2
1
2
6
24

점수

Test cases 4-5 satisfy N6N\le 6.Test cases 6-7 satisfy K=0K=0.Test cases 8-12 satisfy K=1K=1.Test cases 13-24 satisfy K=2K=2.

코드 제출

코드를 제출하려면 로그인이 필요합니다.

로그인
내 제출
제출 내역이 없습니다.
맞은 사람
아직 맞은 사람이 없습니다.
난이도 투표
Unrated0명 투표
로그인 후 AC 받으면 투표할 수 있습니다.
전체 제출
제출 내역이 없습니다.