Permutation Counting

TimeLimit:6000MS  MemoryLimit:262144KB
64-bit integer IO format:%I64d
未提交 | 登录后收藏
Problem Description
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$.
Input
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$.
Output
For each test case:

Output one integer indicating the answer module $10^9 + 7$.
SampleInput
2
3
1 0
5
1 0 0 1
SampleOutput
2
11
Submit
题目统计信息详细
总AC数0
通过人数0
尝试人数0
总提交量0
AC率0.00%
AC该题后可以添加标签
贴完标签可以获得20ACB。
并且可以获得本题所有提交代码查看权限。
点击标题可以显示标签。
如果你还没认真思考过这题,请不要查看标签
如果您已经通过了该题,请务为该题贴上标签

T^T Online Judge

[BUG反馈] [FAQ] [闽ICP备17026590号-1]
当前版本:3.24 系统时间: