#P6689. 序列
序列
Description
Little C came up with a problem about a bracket sequence, but he is not very good at generating testdata, so he uses a random method.
Little C fixes the length of a bracket sequence . Initially, is all (.
He also sets a parameter at the beginning, and then performs the following random process until :
- Uniformly randomly choose an integer in , and flip the bracket at this position in (a left bracket becomes a right bracket, and a right bracket becomes a left bracket).
- If this operation decreases the number of
(, then decrease by .
Now the testdata is generated, and the problem is finished.
Little C asks you to compute the expected length, modulo , of the longest valid bracket subsequence (not necessarily contiguous) in after the above operations.
Input Format
The first line contains two positive integers , whose meanings are given in the statement.
Output Format
Output one line containing one non-negative integer, which is the answer modulo .
2 2
499122177
4 2
873463811
1919 810
488346634
Hint
Sample Explanation 1
In the end there are only possible bracket sequences: )), (), and )(. Their probabilities are , , and , respectively.
The lengths of their longest valid bracket subsequences are , respectively. Therefore the final answer is , i.e. .
Constraints:
For the first of the testdata, .
For another of the testdata, .
For another of the testdata, , .
For another of the testdata, , .
For another of the testdata, , .
For another of the testdata, , .
For all the testdata, it is guaranteed that .
Translated by ChatGPT 5
京公网安备 11011102002149号