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

建议使用的浏览器:

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

7174:Link with Bracket Sequence II

题目描述
Link has a bracket sequence of length $n$. Today, Link finds out that some brackets of the sequence were lost.

Of course, he wants you to calculate how many ways are there to fill the sequence so that it will be a valid bracket sequence.

Note that there are $m$ types of brackets in Link's world.

Here's the definition of a valid bracket sequence:

· A sequence of length $0$ is a valid bracket sequence.
· If $A$ is a valid bracket sequence, $x$ is some type of left bracket, $y$ is the same type of right bracket, $xAy$ is a valid bracket sequence.
· If $A,B$ are both valid bracket sequences, then $AB$ is also a valid bracket sequence.
输入解释
Each test contains multiple test cases. The first line contains the number of test cases $T(1 \le T \le 20)$. Description of the test cases follows.

The first line contains two integers $n(1 \leq n \leq 500),m(1 \leq m < 10^9+7)$, which is the length of Link's bracket sequence and the types of brackets.

The second line contains $n$ integers $a_1,a_2,\ldots,a_n(|a_i| \leq m)$. The $i$-th integer $a_i$ describes the $i$-th character in the sequence:

· If $a_i=0$, it means the bracket in this position is lost.
· $a_i>0$, it means the $i$-th character in the sequence is the $a_i$-th type of left bracket.
· $a_i<0$, it means the $i$-th character in the sequence is the $-a_i$-th type of right bracket.

It is guaranteed that there are at most 15 test cases with $n>100$.
输出解释
For each test case, output one integer in a line, which is the number of ways to fill the bracket sequence so that it is a valid bracket sequence. Since the answer can be huge, just print it modulo $10^9+7$.

For some reason, there could be no way to make it a valid bracket sequence.
输入样例
3
4 2
1 0 0 -1
4 2
0 0 0 -1
6 3
0 0 0 0 0 0
输出样例
3
4
135

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

源链接: HDU-7174

最后修改于 2022-09-15T06:17:10+00:00 由爬虫自动更新

共提交 0

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