Codeforces Round 1091 (Div. 2) and CodeCraft 26
G
Down the Pivot
Codeforces
2600
原题
← FH →
翻译中…

Consider binary trees where each node has at most two children, and each node is labeled with either $0$ or $1$.

翻译中…

In one operation, you can flip all the labels on any simple path that passes through the root. Flipping a label means changing $0$ to $1$ and $1$ to $0$. Note that a path of length $1$ containing only the root is also allowed.

翻译中…

The cost of such a binary tree is defined as the minimum number of operations required to make all labels in the tree equal to $0$.

翻译中…

Given two integers $n$ and $k$, count the number of distinct labeled binary trees with exactly $n$ nodes and cost exactly $k$. Since the answer can be very large, output it modulo $10^9 + 7$.

翻译中…

Two binary trees are considered distinct if they have different structures, or if they have the same structure but differ in at least one node's label.

翻译中…

Input

翻译中…

Each test contains multiple test cases. The first line contains the number of test cases $t$ ($1 \le t \le 10^4$). The description of the test cases follows.

翻译中…

The only line of each test case contains two integers $n$ and $k$ ($1 \le n \le 10^6$, $0 \le k \le n$).

翻译中…

It is guaranteed that the sum of $n$ over all test cases does not exceed $10^6$.

翻译中…

Output

翻译中…

For each test case, output a single integer on a new line — the number of labeled binary trees with $n$ nodes and cost $k$, modulo $10^9+7$.

翻译中…

Note

翻译中…

In the first test case, we have $n=2$ and $k=0$. There are two possible trees—a root with a left child and a root with a right child. Since we need a cost of $0$, all nodes must be labeled $0$. Thus, the answer is $2$.

翻译中…

In the second test case, $n=2$ and $k=1$. There are $4$ such trees. The valid labeled trees are shown in the figure below:

翻译中…

image

翻译中…

In the third test case, $n=1$ and $k=1$. There is only one tree—a single root node with label $1$. Thus, the answer is $1$.

翻译中…

样例

Input #1
6
2 0
2 1
1 1
7 6
69 67
314159 42
Output #1
2
4
1
2016
382216284
559671824
InputCopy OutputCopy
题目信息
题号
2217G
时间限制
2 s
内存限制
256 MB
标签
组合数学
动态规划
数学
树

题面与样例版权归 Codeforces 及出题人所有;中文翻译由 AI 生成(CI 管线),如有出入请以原文为准。