CF1761D.Carry Bit
提高+/省选-
通过率:0%
时间限制:1.00s
内存限制:256MB
AC君温馨提醒
该题目为【codeforces】题库的题目,您提交的代码将被提交至codeforces进行远程评测,并由ACGO抓取测评结果后进行展示。由于远程测评的测评机由其他平台提供,我们无法保证该服务的稳定性,若提交后无反应,请等待一段时间后再进行重试。
题目描述
Let f(x,y) be the number of carries of x+y in binary (i. e. f(x,y)=g(x)+g(y)−g(x+y), where g(x) is the number of ones in the binary representation of x).
Given two integers n and k, find the number of ordered pairs (a,b) such that 0≤a,b<2n, and f(a,b) equals k. Note that for a=b, (a,b) and (b,a) are considered as two different pairs.
As this number may be large, output it modulo 109+7.
设 f(x,y) 表示 x+y 在二进制加法中产生的进位次数(即 f(x,y)=g(x)+g(y)−g(x+y),其中 g(x) 表示 x 的二进制表示中 1 的个数)。
给定两个整数 n 和 k,求满足 0≤a,b<2n 且 f(a,b)=k 的有序对 (a,b) 的个数。注意:当 a=b 时,(a,b) 与 (b,a) 被视为两个不同的有序对。
由于该数目可能很大,请输出其对 109+7 取模的结果。
输入格式
The only line of each test contains two integers n and k (0≤k<n≤106).
每组测试数据仅包含一行,其中有两个整数 n 和 k(0≤k<n≤106)。
输出格式
Output a single integer — the answer modulo 109+7.
输出一个整数——答案对 109+7 取模的结果。
输入输出样例
输入#1
3 1
输出#1
15
输入#2
3 0
输出#2
27
输入#3
998 244
输出#3
573035660
说明/提示
Here are some examples for understanding carries:
\\begin{aligned} &\\begin{array}{r} 1\_{\\ \\ }1\_{\\ \\ }1\\\\ +\\ \_{1}1\_{\\ \\ }0\_{\\ \\ }0\\\\ \\hline \\ 1\_{\\ \\ }0\_{\\ \\ }1\_{\\ \\ }1 \\end{array} &\\begin{array}{r} \\ 1\_{\\ \\ }0\_{\\ \\ }1\\\\ +\\ \_{\\ \\ }0\_{\\ \\ }0\_{1}1\\\\ \\hline \\ 0\_{\\ \\ }1\_{\\ \\ }1\_{\\ \\ }0 \\end{array} & &\\begin{array}{r} \\ 1\_{\\ \\ }0\_{\\ \\ }1\\\\ +\\ \_{1}0\_{1}1\_{1}1\\\\ \\hline \\ 1\_{\\ \\ }0\_{\\ \\ }0\_{\\ \\ }0 \\end{array} \\end{aligned}So f(7,4)=1, f(5,1)=1 and f(5,3)=3.
In the first test case, all the pairs meeting the constraints are (1,1),(1,5),(2,2),(2,3),(3,2),(4,4),(4,5),(4,6),(4,7),(5,1),(5,4),(5,6),(6,4),(6,5),(7,4).
以下是一些关于进位的理解示例:
1_ 1_ 1+ 11_ 0_ 0 1_ 0_ 1_ 1 1_ 0_ 1+ _ 0_ 0_11 0_ 1_ 1_ 0 1_ 0_ 1+ 10_11_11 1_ 0_ 0_ 0
因此,f(7,4)=1,f(5,1)=1,且 f(5,3)=3。
在第一个测试用例中,满足约束条件的所有数对为:(1,1),(1,5),(2,2),(2,3),(3,2),(4,4),(4,5),(4,6),(4,7),(5,1),(5,4),(5,6),(6,4),(6,5),(7,4)。
输入解题思路,AI测评打分。不知道怎么写?