CF2217G.Down the Pivot

省选/NOI-

通过率:0%

AC君温馨提醒

该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。

题目描述

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.

输入格式

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 $ .

输出格式

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 $ .

输入输出样例

  • 输入#1

    6
    2 0
    2 1
    1 1
    7 6
    69 67
    314159 42

    输出#1

    2
    4
    1
    2016
    382216284
    559671824

说明/提示

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:

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 $ .

输入解题思路,AI测评打分。不知道怎么写?

首页