博客
关于我
CF #716 (Div. 2) B. AND 0, Sum Big(思维+数学)
阅读量:281 次
发布时间:2019-03-01

本文共 1585 字,大约阅读时间需要 5 分钟。

Baby Badawy's first words were "AND 0 SUM BIG", so he decided to solve the following problem. Given two integers nn and kk, count the number of arrays of length nn such that:

  • all its elements are integers between 00 and 2k−1 (inclusive);
  • the  of all its elements is 00;
  • the sum of its elements is as large as possible.

Since the answer can be very large, print its remainder when divided by 109+7109+7.

Input

The first line contains an integer tt (1≤t≤10) — the number of test cases you need to solve.

Each test case consists of a line containing two integers nn and kk (1≤n≤105, 1≤k≤20).

Output

For each test case, print the number of arrays satisfying the conditions. Since the answer can be very large, print its remainder when divided by 109+7

Example

input

Copy

22 2100000 20

output

Copy

4226732710

Note

In the first example, the 44 arrays are:

  • [3,0],
  • [0,3],
  • [1,2],
  • [2,1].

题目大意:给你n和k,n是数组的长度,现在给你构造一个长度为n 的序列的三个条件,一个是序列中每个元素的值在0到2^k-1,二是所有元素与的值为0,三是让序列元素的和尽可能地大,问满足上述三个条件的序列有几个

解题思路: 

题目告诉你数组中的每个数大于0小于2^k-1,又告诉你所以的结果玉等于零,那么我们很容易就想到将数转化为二进制思考问题,要是数组的和尽可能地大,那么数组中的每个数就尽可能地大,转化为二进制就是每个数的二进制位都是1.但是全为1就不满足相与为0,则我们就要将二进制位中的1位1转化为0,而且只能最多转化1位,因为转化的多了就不满足元素之和尽可能大了,我们现在有n个数,每个数有k位,那么答案就显而易见是 n^k

下面附上ac代码

#include 
#include
#include
#include
#include
#include
#include
using namespace std;typedef long long ll;#define M 1000000const int mod=1e9+7;ll a[3];int main(){ std::ios::sync_with_stdio(false); cin.tie(0),cout.tie(0); ll t; cin>>t; while(t--) { ll n,k,ans=1; cin>>n>>k; for(ll i=1;i<=k;i++) { ans=(ans*n)%mod; } cout<
<

 

转载地址:http://nzlo.baihongyu.com/

你可能感兴趣的文章
mysql面试题学校三表查询_mysql三表查询分组后取每组最大值,mysql面试题。
查看>>
Mysql面试题精选
查看>>
MySQL面试题集锦
查看>>
mysql面试题,存储引擎InnoDB和MyISAM
查看>>
mysql面试题:为什么MySQL单表不能超过2000W条数据?
查看>>
mysql面试题:创建索引时会不会锁表?
查看>>
mysql面试题:高度为3的B+树可以存放多少数据?
查看>>
mysql颠覆实战笔记(八)--mysql的自定义异常处理怎么破
查看>>
mysql驱动、durid、mybatis之间的关系
查看>>
mysql驱动支持中文_mysql 驱动包-Go语言中文社区
查看>>
MySQL高可用之——keepalived+互为主从
查看>>
MySQL高可用切换_(5.9)mysql高可用系列——正常主从切换测试
查看>>
MySQL高可用解决方案
查看>>
MySQL高可用解决方案详解
查看>>
MYSQL高可用集群MHA架构
查看>>
MySQL高可用集群架构MHA企业级实战
查看>>
MySQL高级-MySQL存储引擎
查看>>
MySQL高级-MySQL并发参数调整
查看>>
MySQL高级-MySQL应用优化
查看>>
MySQL高级-MySQL查询缓存优化
查看>>