Hard to prepare

  • 28.63%
  • 1000ms
  • 262144K
 

After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a Nogaku show during the feast. To enjoy the show, every audience has to wear a Nogaku mask, and seat around as a circle.

There are N guests Reimu serves. Kokoro has 2^k2k masks numbered from 0,1,\cdots,0,1,⋯, 2^k - 12k−1, and every guest wears one of the masks. The masks have dark power of Dark Nogaku, and to prevent guests from being hurt by the power, two guests seating aside must ensure that if their masks are numbered ii and jj , then ii XNOR jj must be positive. (two guests can wear the same mask). XNOR means ~(ii^jj) and every number has kk bits. (11 XNOR 1 = 11=1, 00 XNOR 0 = 10=1, 11 XNOR 0 = 00=0)

You may have seen 《A Summer Day's dream》, a doujin Animation of Touhou Project. Things go like the anime, Suika activated her ability, and the feast will loop for infinite times. This really troubles Reimu: to not make her customers feel bored, she must prepare enough numbers of different Nogaku scenes. Reimu find that each time the same guest will seat on the same seat, and She just have to prepare a new scene for a specific mask distribution. Two distribution plans are considered different, if any guest wears different masks.

In order to save faiths for Shrine, Reimu have to calculate that to make guests not bored, how many different Nogaku scenes does Reimu and Kokoro have to prepare. Due to the number may be too large, Reimu only want to get the answer modules 1e9+71e9+7 . Reimu did never attend Terakoya, so she doesn't know how to calculate in module. So Reimu wishes you to help her figure out the answer, and she promises that after you succeed she will give you a balloon as a gift.

Input

First line one number TT , the number of testcases; (T \le 20)(T≤20) .

Next TT lines each contains two numbers, NN and k(0<N, k \le 1e6)k(0<N,k≤1e6) .

Output

For each testcase output one line with a single number of scenes Reimu and Kokoro have to prepare, the answer modules 1e9+71e9+7 .

样例输入复制

2
3 1
4 2

样例输出复制

2
84

题目来源

ACM-ICPC 2018 徐州赛区网络预赛

#include<bits/stdc++.h>
#define MAX 1000005
#define MOD 1000000007
using namespace std;
typedef long long ll; ll dp[MAX]; ll qMod(ll a,ll b)
{
ll ans=;
a%=MOD;
while(b){
if(b&) ans=ans*a%MOD;
b>>=;
a=a*a%MOD;
}
return ans;
}
int main()
{
int t,i,j;
ll n,k;
scanf("%d",&t);
while(t--){
scanf("%lld%lld",&n,&k);
dp[] = qMod(2ll,k);
ll temp1 = (dp[]-+MOD)%MOD;
ll temp2 = (dp[]-+MOD)%MOD;
dp[] = dp[]*temp1%MOD;
for(i=;i<=n;i++){
dp[i]=(dp[i-]*temp1%MOD+(dp[i-]-dp[]+MOD)%MOD*temp2%MOD)%MOD;
}
printf("%lld\n",dp[n]);
}
return ;
}

ACM-ICPC2018徐州网络赛 Hard to prepare(dp)的更多相关文章

  1. 徐州网络赛A-Hard To Prepare【dp】【位运算】【快速幂】

    After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a ...

  2. 2018 ICPC 徐州网络赛

    2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...

  3. 计蒜客 41391.query-二维偏序+树状数组(预处理出来满足情况的gcd) (The Preliminary Contest for ICPC Asia Xuzhou 2019 I.) 2019年徐州网络赛)

    query Given a permutation pp of length nn, you are asked to answer mm queries, each query can be rep ...

  4. ICPC 2019 徐州网络赛

    ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...

  5. [徐州网络赛]Longest subsequence

    [徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...

  6. 徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】

    In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...

  7. 徐州网络赛J-Maze Designer【最小生成树】【LCA】

    After the long vacation, the maze designer master has to do his job. A tour company gives him a map ...

  8. 徐州网络赛G-Trace【线段树】

    There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy  ...

  9. 徐州网络赛H-Ryuji doesn't want to study【线段树】

    Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, ea ...

随机推荐

  1. Hibernate性能优化

    1.性能是与具体的项目挂钩的,并不是对于A项目某种优化方法好就适用于B项目.性能需要不断的测试检验出来的.....(废话) 2.session.clear()方法的使用,通常session是有缓存的 ...

  2. 九度OJ 1158:买房子 (基础题)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:1801 解决:1096 题目描述: 某程序员开始工作,年薪N万,他希望在中关村公馆买一套60平米的房子,现在价格是200万,假设房子价格以每 ...

  3. 九度OJ 1066:字符串排序 (排序)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5632 解决:2299 题目描述: 输入一个长度不超过20的字符串,对所输入的字符串,按照ASCII码的大小从小到大进行排序,请输出排序后的 ...

  4. python中的特殊用法

    1 别名 from xxx import xxx as xxx;

  5. protobuf + maven 爬坑记

    疯狂创客圈 死磕Netty 亿级流量架构系列之20 [博客园 总入口 ] 本文说明 本篇是 netty+Protobuf 整合实战的 第一篇,完成一个 基于Netty + Protobuf 实战案例. ...

  6. squared-error loss is much more repaidly updated than mean-absolute-deviation when searching for splits

    平方差损失能较绝对值差损失更快地更新

  7. 警告: [SetPropertiesRule]{Server/Service/Engine/Host/Context} Setting property 'source' to 'org.eclipse.jst.jee.server:Zhuo' did not find a matching property.

    eclipse里面配置tomcat方法:window -- show view -- other -- 找到servers 点击finish 就会出现servers选项卡在选项卡中右键鼠标 new - ...

  8. oracle-jforum论坛链接Oracle

    问题描述 jforum论坛链接Oracle jforum论坛链接Oracle数据库 论坛主题页面不显示 是权限引起的吗 解决方案 页面不显示,你需要看一下错误,估计是配置不对引起的 参考一下这个 jf ...

  9. Delphi编写WebService体会

    源:Delphi编写WebService体会 Dispatch: 派遣,分派 Invoke: 调用 Invokable: 可调用接口 TReomtable: WebService中自定义类都是继承自该 ...

  10. win 10 安装.msi 程序出现the error code is 2503

    解决方法: C:\Windows\temp文件夹的权限不够,需要给其更高权限 右键temp文件夹 点击属性进入属性对话框 组或用户名的里面的All APPLICATION PACKAGES和所有受限制 ...