#P7869. Permutation Counting
Permutation Counting
Permutation Counting
Problem Description
For a given permutation of length , we defined the neighbor sequence of , the length of which is , as following:
$$b_i= \begin{cases}0~~~a_i\text{ < } a_{i+1} \\ 1~~~a_i>a_{i+1}\end{cases} $$For example, the neighbor sequence of permutation is . Now we give you an integer and a sequence of length , you should calculate the number of permutations of length whose neighbor sequence equals to . To avoid calculation of big number, you should output the answer module .
Input
The first line contains one positive integer (), denoting the number of test cases. For each test case: The first line of the input contains one integer . The second line of the input contains integer: There are no more than cases with .
Output
For each test case: Output one integer indicating the answer module .
Sample Input
2
3
1 0
5
1 0 0 1
Sample Output
2
11
Source
2020 Multi-University Training Contest 10
>