7576: Kcats

内存限制:512 MB 时间限制:5 S
题面:传统 评测方式:文本比较 上传者:
提交:0 通过:0

题目描述

Notice:Don't output extra spaces at the end of one line.

Let p1,p2,⋯,pn be a permutation of length n, Dodo bird built an array a of length n where ai indicates the size of the monotonic stack got from p1,p2,⋯,pi. For instance, if p is 3,1,4,5,6,2, we add the elements in the permutation to the monotonic stack one by one, the changes of the monotonic stack is as follows:

3→1→1,4→1,4,5→1,4,5,6→1,2


So the corresponding array a is 1,1,2,3,4,2.

Years later, Dodo bird found the array a, but the value in some positions cannot be recognized anymore. He wants to know how many permutations can possibly be the original permutation. As the answer can be very large, you only need to output the answer module 109+7.

输入格式

The first line contains a number T(1≤T≤100), indicating the number of test cases.

Each test case contains two lines. The first line contains an integer n(1≤n≤100), indicating the length of the permutation. The second line contains n integers a1,a2,⋯,an(−1≤ai≤n,ai≠0), indicating the array aai=−1 represents that the value of this position cannot be recognized.

输出格式

T lines, each line is an integer, indicating the answer module 109+7.

输入样例 复制

5
6
1 1 2 3 4 2
3
1 2 3
3
-1 -1 -1
3
1 1 1
3
3 3 3

输出样例 复制

5
1
6
1
0

数据范围与提示