博客
关于我
CF #716 (Div. 2) B. AND 0, Sum Big(思维+数学)
阅读量:267 次
发布时间: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/

你可能感兴趣的文章
2021年美容师(初级)考试报名及美容师(初级)新版试题
查看>>
2021年N1叉车司机考试题及N1叉车司机复审模拟考试
查看>>
2021年危险化学品经营单位主要负责人考试APP及危险化学品经营单位主要负责人多少钱
查看>>
2021年T电梯修理考试技巧及T电梯修理模拟考试软件
查看>>
2021年R2移动式压力容器充装考试题及R2移动式压力容器充装找答案
查看>>
2021年电工(初级)考试及电工(初级)证考试
查看>>
2021年安全员-B证-项目负责人(广东省)新版试题及安全员-B证-项目负责人(广东省)考试试卷
查看>>
2021年安全员-B证(山东省)考试APP及安全员-B证(山东省)考试技巧
查看>>
2021年安全员-A证-主要负责人(广东省)复审考试及安全员-A证-主要负责人(广东省)操作证考试
查看>>
2021年安全员-A证(山东省)考试题及安全员-A证(山东省)报名考试
查看>>
2021年G1工业锅炉司炉考试报名及G1工业锅炉司炉模拟考试题库
查看>>
大数据学习之Spark——00Spark项目的pom.xml文件
查看>>
大数据学习之Spark——01Spark概述
查看>>
从 MFC 移植程序到 wxWidgets 界面库 ——《定时执行专家 5.0》的界面实现
查看>>
CodeBlocks开发wxWidgets环境配置详细
查看>>
Qt 转向 LGPL之后,wxWidgets 路在何方
查看>>
wxSqlite3 和 wxPropertyGrid 类库的说明
查看>>
天涯人脉通讯录 - 设计草图
查看>>
wxWidgets 最新版2.8.11,终于放出来了
查看>>
python学习09:暂停一秒后再输出
查看>>