No.1662 (ox) Alternative
Problem Statement
Among the strings of length $A+B+C+D$ consisting of $A$ copies of (, $B$ copies of ), $C$ copies of o, and $D$ copies of x, find the number of those satisfying the following condition, modulo $10^9+7$.
- The string obtained by replacing every occurrence of
owith()and every occurrence ofxwith)(is a balanced parenthesis string.
Answer for $T$ test cases.
▼ (Definition of a balanced parenthesis string)
A balanced parenthesis string is a string satisfying one of the following conditions.
- It is the empty string.
- There exist non-empty balanced parenthesis strings $s,t$, and it is the string obtained by concatenating $s,t$ in this order.
- There exists a balanced parenthesis string $s$, and it is the string obtained by concatenating
(, $s$,)in this order.
Constraints
- $1\le T\le 10^5$
- $0\le A,B,C,D\le 10^5$
- $A+B+C+D\ge 1$
- All input values are integers.
Input
$T$
$\text{case}_1$
$\text{case}_2$
$\vdots$
$\text{case}_T$
Each test case is given in the following format.
$A$ $B$ $C$ $D$
Output
Output $T$ lines. On the $i$-th line, output the answer for the $i$-th test case.
Sample
Sample 1
Input
3 1 1 1 1 31 41 59 26 999 999 0 1234
Output
4 0 479533106
(Test case $1$) There are $4$ such strings: (ox), (xo), o(x), (x)o.
(Test case $2$) There is not even $1$ such string.
(Test case $3$) Output the remainder when divided by $10^9+7$.
提出するには、Twitter 、GitHub、 Googleもしくは右上の雲マークをクリックしてアカウントを作成してください。
LayCurse