ACM-ICPC2018徐州网络赛 Hard to prepare(dp)
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
题目来源
#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)的更多相关文章
- 徐州网络赛A-Hard To Prepare【dp】【位运算】【快速幂】
After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked Kokoro to deliver a ...
- 2018 ICPC 徐州网络赛
2018 ICPC 徐州网络赛 A. Hard to prepare 题目描述:\(n\)个数围成一个环,每个数是\(0\)~\(2^k-1\),相邻两个数的同或值不为零,问方案数. solution ...
- 计蒜客 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 ...
- ICPC 2019 徐州网络赛
ICPC 2019 徐州网络赛 比赛时间:2019.9.7 比赛链接:The Preliminary Contest for ICPC Asia Xuzhou 2019 赛后的经验总结 // 比赛完才 ...
- [徐州网络赛]Longest subsequence
[徐州网络赛]Longest subsequence 可以分成两个部分,前面相同,然后下一个字符比对应位置上的大. 枚举这个位置 用序列自动机进行s字符串的下标转移 注意最后一个字符 #include ...
- 徐州网络赛B-BE,GE or NE【记忆化搜索】【博弈论】
In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl named &qu ...
- 徐州网络赛J-Maze Designer【最小生成树】【LCA】
After the long vacation, the maze designer master has to do his job. A tour company gives him a map ...
- 徐州网络赛G-Trace【线段树】
There's a beach in the first quadrant. And from time to time, there are sea waves. A wave ( xx , yy ...
- 徐州网络赛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 ...
随机推荐
- HTML 学习笔记 JQuery(DOM 操作3)
设置和获取HTML 文本 和 值 1.html()方法 类似于JavaScript中的innerHTML属性,可以用来读取或者设置某个元素中的HTML内容 例子 <html> <he ...
- Grunt学习笔记【8】---- grunt-angular-templates插件详解
本文主要讲如何用Grunt打包AngularJS的模板HTML. 一 说明 AngularJS中使用单独HTML模板文件的地方非常多,例如:自定义指令.ng-include.templateUrl等. ...
- ME11创建信息记录 Function
转自 http://blog.csdn.net/zeewjj/article/details/7941530 CALL FUNCTION 'ME_DIRECT_INPUT_INFORECORD' D ...
- SIFT算法详解(转)
原文地址 http://blog.csdn.net/pi9nc/article/details/23302075 尺度不变特征变换匹配算法详解 Scale Invariant Feature Tran ...
- vue 升降排序
本实例是根据工作进度的百分比来进行排序. html <div class="ibox-content"> <li v-for="(rangeItem,i ...
- python的上下文管理器
直接上代码: f = open('123.txt','w') try: f.write('hello world') except Exception: pass finally: f.close() ...
- tflearn 在每一个epoch完毕保存模型
关键代码:tflearn.DNN(net, checkpoint_path='model_resnet_cifar10', max_checkpoints=10, tensorboard_verbos ...
- [原创]java向word模板中填充数据(总结)
使用过PageOffice动态生成word文档的人都知道,PageOffice可以给word文档的指定位置进行填充,这里我们所说的指定位置在PageOffice的专业术语里面有两个概念,一个叫做数据区 ...
- HihoCoder1643 : 最少换乘([Offer收割]编程练习赛37)(bfs)
描述 小Ho居住的城市有N条公交车线路,其中第i条线路上有Ki个车站. 某些线路之间会有公共的车站,小Ho可以在这些车站从一条线路换乘到另一条线路. 现在给定N条公交车线路以及两个车站S和E,你能帮助 ...
- Oracle表空间维护总结
1. 概念:表空间:最大的逻辑存储文件,与物理上的一个或多个数据文件对应,每个数据库至少拥有一个表空间,表空间的大小等于构成表空间的所有数据文件的大小总和,用于存储用户在数据库中存储的所有内容. 2. ...