No.3213 depth max K
Problem Statement
Among the correct bracket sequences of length $2N$, how many have "the depth of the deepest part of the bracket sequence" equal to exactly $K$?
What is a correct bracket sequence?
A correct bracket sequence is a non-empty string satisfying one of the following conditions.()- A string obtained by concatenating
($,A,$)in this order, for some correct bracket sequence $A$ - A string obtained by concatenating $A,B$ in this order, for some correct bracket sequences $A,B$
Since the answer can be very large, report it modulo $998244353$.
Here, "the depth of the deepest part of the bracket sequence" is a quantity defined by processing a correct bracket sequence according to the following procedure. Incorrect bracket sequences are not considered here.
Prepare variables $\text{depth},\text{ans}$ and initialize them as $\text{depth} = 0,\text{ans} = 0$.
Perform the following operation for each character in order, from the beginning to the end of the bracket sequence.
- If the current character is
(, increase the variable $\text{depth}$ by $1$. Otherwise, if the current character is), decrease the variable $\text{depth}$ by $1$. - If $\text{ans}$ is less than $\text{depth}$, assign $\text{depth}$ to $\text{ans}$.
- If the current character is
The value of $\text{ans}$ at this point is defined as "the depth of the deepest part of the bracket sequence".
For example, "the depth of the deepest part of the bracket sequence" is $2$ for (())(), and $4$ for ((()(()))).
Constraints
- $1 \leq N \leq 5000 $
- $1 \leq K \leq N $
- All values in the input are integers
Input
$N$ $K$
Output
Output the answer modulo $998244353$.
Sample
Sample 1
Input
3 2
Output
3
There are $3$ such sequences: (())(),()(()),(()()).
Sample 2
Input
1 1
Output
1
There is $1$ such sequence: ().
Sample 3
Input
21 10
Output
87633350
The true value is $1085877703$, but you should output $87633350$, its remainder modulo $998244353$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
Cafe1942