当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

6854:Kcats

题目描述
Notice:Don't output extra spaces at the end of one line.

Let $p_1, p_2, \cdots, p_n$ be a permutation of length $n$, Dodo bird built an array $a$ of length $n$ where $a_i$ indicates the size of the monotonic stack got from $p_1, p_2, \cdots, p_i$. 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 \to 1 \to 1,4 \to 1,4,5 \to 1,4,5,6 \to 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 $10^9+7$.
输入解释
The first line contains a number $T(1 \leq T \leq 100)$, indicating the number of test cases.

Each test case contains two lines. The first line contains an integer $n(1 \leq n \leq 100)$, indicating the length of the permutation. The second line contains $n$ integers $a_1, a_2, \cdots, a_n(-1 \leq a_i \leq n, a_i \not= 0)$, indicating the array $a$. $a_i=-1$ represents that the value of this position cannot be recognized.
输出解释
$T$ lines, each line is an integer, indicating the answer module $10^9 + 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
来自杭电HDUOJ的附加信息
Recommend IceyWang

该题目是Virtual Judge题目,来自 杭电HDUOJ

源链接: HDU-6854

最后修改于 2020-10-25T23:34:57+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
5000/5000MS(Java/Others) 524288/524288K(Java/Others)