题目描述
Problem Description
Little C has come up with a problem about bracket sequences, but he is not very good at creating test data, so he decided to use a random approach.
Little C specified the length \( N \) of the bracket sequence \( S \). Initially, \( S \) is filled with (.
He set an initial parameter \( K \) and follows the following random process until \( K = 0 \):
- Uniformly randomly select an integer within the range \([1, N]\) and invert the bracket at that position in \( S \) (change
(to)and vice versa). - If this operation reduces the number of
(, decrement \( K \) by 1.
Now the data is created, and the problem is set.
Little C would like you to find the expected length of the longest valid subsequence (not necessarily contiguous) in \( S \) after the above operations, modulo \( 998244353 \).
Input Format
The first line of input contains two positive integers \( N \) and \( K \), as described in the problem statement.
Output Format
Output a single non-negative integer, which is the result of your calculation modulo \( 998244353 \).
Sample Input and Output
Sample Input #1
2 2
Sample Output #1
499122177
Sample Input #2
4 2
Sample Output #2
873463811
Sample Input #3
1919 810
Sample Output #3
488346634
Notes
Sample Explanation 1
The final bracket sequences can be )), (), or )( with probabilities \(\frac{1}{2}\), \(\frac{1}{4}\), and \(\frac{1}{4}\) respectively.
Their corresponding longest valid subsequence lengths are \(0, 2, 0\). Therefore, the final answer is \(\frac{1}{2}\), which is \(499122177\).
Data Range:
For the first \(5\%\) of the data, \(N = 1\);
Another \(5\%\) of the data, \(N = 2\);
Another \(5\%\) of the data, \(N \le 7\), \(K \le 5\);
Another \(15\%\) of the data, \(N \le 15\), \(K \le 500\);
Another \(15\%\) of the data, \(N \le 50\), \(K \le 50\);
Another \(15\%\) of the data, \(N \le 500\), \(K \le 100\);
For all data, \(1 \le N, K \le 5000\).
输入格式
见题面 Input 部分
输出格式
见题面 Output 部分