博客
关于我
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中实现rownum,对结果进行排序
查看>>
mysql中对于数据库的基本操作
查看>>
Mysql中常用函数的使用示例
查看>>
MySql中怎样使用case-when实现判断查询结果返回
查看>>
Mysql中怎样使用update更新某列的数据减去指定值
查看>>
Mysql中怎样设置指定ip远程访问连接
查看>>
mysql中数据表的基本操作很难嘛,由这个实验来带你从头走一遍
查看>>
Mysql中文乱码问题完美解决方案
查看>>
mysql中的 +号 和 CONCAT(str1,str2,...)
查看>>
Mysql中的 IFNULL 函数的详解
查看>>
mysql中的collate关键字是什么意思?
查看>>
MySql中的concat()相关函数
查看>>
mysql中的concat函数,concat_ws函数,concat_group函数之间的区别
查看>>
MySQL中的count函数
查看>>
MySQL中的DB、DBMS、SQL
查看>>
MySQL中的DECIMAL类型:MYSQL_TYPE_DECIMAL与MYSQL_TYPE_NEWDECIMAL详解
查看>>
MySQL中的GROUP_CONCAT()函数详解与实战应用
查看>>
MySQL中的IO问题分析与优化
查看>>
MySQL中的ON DUPLICATE KEY UPDATE详解与应用
查看>>