li
Of course, he wants you to calculate how many ways are there to fill the sequence so that it will be a valid bracket sequence.
Note that there are m types of brackets in li
Here's the definition of a valid bracket sequence:
· A sequence of length 0 is a valid bracket sequence. · If A is a valid bracket sequence, x is some type of left bracket, y is the same type of right bracket, xAy is a valid bracket sequence. · If A,B are both valid bracket sequences, then AB is also a valid bracket sequence.
Each test contains multiple test cases. The first line contains the number of test casesT(1≤T≤20). Desc
The first line contains two integers n(1≤n≤500),m(1≤m<109+7), which is the length of li
The second line contains n integers a1,a2,…,an(∣ai∣≤m). The i-th integer ai describes the i-th character in the sequence:
· If ai=0, it means the bracket in this position is lost. · ai>0, it means the i-th character in the sequence is the ai-th type of left bracket. ·ai<0, it means the ii-th character in the sequence is the -aith type of right bracket.
It is guaranteed that there are at most 15 test cases with n>100.
For each test case, output one integer in a line, which is the number of ways to fill the bracket sequence so that it is a valid bracket sequence. Since the answer can be huge, just print it modulo 109+7.
For some reason, there could be no way to make it a valid bracket sequence.
3
4 2
1 0 0 -1
4 2
0 0 0 -1
6 3
0 0 0 0 0 0
3
4
135