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

建议使用的浏览器:

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

6880:Permutation Counting

题目描述
For a given permutation $a_1, a_2, \cdots, a_n$ of length $n$, we defined the neighbor sequence $b$ of $a$, the length of which is $n - 1$, as following:

$$
\begin{equation}

b_i=

\begin{cases}

0 & a_i < a_{i + 1}\\
1 & a_i > a_{i + 1}
\end{cases}

\end{equation}
$$.

For example, the neighbor sequence of permutation $1, 2, 3, 6, 4, 5$ is $0, 0, 0, 1, 0$.

Now we give you an integer $n$ and a sequence $b_1, b_2, \cdots, b_{n - 1}$ of length $n - 1$, you should calculate the number of permutations of length $n$ whose neighbor sequence equals to $b$.


To avoid calculation of big number, you should output the answer module $10^9 + 7$.
输入解释
The first line contains one positive integer $T$ ($1\le T \le 50$), denoting the number of test cases. For each test case:

The first line of the input contains one integer $n, (2 \le n \le 5000)$.

The second line of the input contains $n - 1$ integer: $b_1, b_2, \cdots, b_{n - 1}$

There are no more than $20$ cases with $n > 300$.
输出解释
For each test case:

Output one integer indicating the answer module $10^9 + 7$.
输入样例
2
3
1 0
5
1 0 0 1
输出样例
2
11
来自杭电HDUOJ的附加信息
Recommend IceyWang

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

源链接: HDU-6880

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

共提交 0

通过率 --%
时间上限 内存上限
12000/6000MS(Java/Others) 262144/262144K(Java/Others)