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

建议使用的浏览器:

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

5827:Rikka with Parenthesis

题目描述
As we know, Rikka is poor at math. Yuta is worrying about this situation, so he gives Rikka some math tasks to practice. There is one of them:

Correct parentheses sequences can be defined recursively as follows:
1.The empty string "" is a correct sequence.
2.If "X" and "Y" are correct sequences, then "XY" (the concatenation of X and Y) is a correct sequence.
3.If "X" is a correct sequence, then "(X)" is a correct sequence.
Each correct parentheses sequence can be derived using the above rules.
Examples of correct parentheses sequences include "", "()", "()()()", "(()())", and "(((())))".

For a parentheses sequence, Rikka can make some operations on it. Each time she can choose two indices L and R such that L <= R. The operation modifies the characters on indices from L to R, inclusive. First, the order of these characters is reversed. Then, each character is toggled to the opposite one. That is, each '(' in the specified range changes to a ')' and vice versa.

The value of a parentheses sequence is the minimal number of the operations to change it to a correct parentheses sequence. If it is impossible, the value of the sequence is equal to 10^100.

For example, The value of '()((' is 1, the value of '()()' is 0 and the value of '(((' is 10^100.

Now Yuta shows two numbers n and m, For each K in [0,n], he wants to know the number of the different parentheses sequence of length n which has value K. The answer may be very large, he only wants to know the answer module m.

It is too difficult for Rikka. Can you help her?
输入解释
The first line contains a number t(1<=t<=10), the number of the testcases. For each testcase, the first line contains two integers n,m (1<=n<=10^6,1<=m<=10^9).
输出解释
For each testcase, print a line contains a single number. Let A[i] be the answer when K=i, you need to output $(\sum_{i=0}^n (i+1) \times A[i]) \mod m$.
输入样例
1
10 100
输出样例
68
来自杭电HDUOJ的附加信息
Author 学军中学
Recommend wange2014

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

源链接: HDU-5827

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

共提交 0

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