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 ...
随机推荐
- Locality-sensitive hashing Pr[m(Si) = m(Sj )] = E[JSˆ (Si, Sj )] = JS(Si, Sj )
A hash function that maps names to integers from 0 to 15. There is a collision between keys "Jo ...
- Java for LeetCode 101 Symmetric Tree
Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center). For e ...
- nginx语法之location详解
Location语法优先级排列 匹配符 匹配规则 优先级 = 精确匹配 ^~ 以某个字符串开头 ~ 区分大小写的正则匹配 ~* 不区分大小写的正则匹配 !~ 区分大小写不匹配的正则 !~* 不区分大小 ...
- Ubuntu/CentOS下使用脚本自动安装 Docker
Ubuntu.Debian 系列安装 Docker 系统要求 Docker 支持以下版本的 Ubuntu 和 Debian 操作系统: Ubuntu Xenial 16.04 (LTS) Ubuntu ...
- uboot 2013.01 代码简析(2)第一阶段初始化
uboot执行"make smdk2410_config"之后就可以进行编译了,可以执行make命令进行编译, 因为整个输出太长,我仅仅列出部分最关键的输出(部分我不关心的内容直接 ...
- stm32f429I discovery试用
从网上了解到stm32f429I discovery可以跑单片机程序也可以跑uclinux,而我恰好喜爱嵌入式开发相关内容, 性价比也较高,所以新入手了这款开发板.开发板官方网页:http://www ...
- Contiki 2.7 Makefile 文件(一)
一.主控Makefile 这里以hello-world例子为主线,从其工程Makefile开始,解析整个build过程.
- Contiki-Timer 概述
Contiki有一个clock模块和一系列timer模块:timer,stimer,ctimer,etimer,和rtimer. 一.clock模块 clock模块提供一些处理系统时间的函数,还有一些 ...
- deepin 安装微信与QQ
安装QQ sudo apt-get install deepin.com.qq.im 安装微信 sudo apt-get install deepin.com.wechat 附录 其他安装包 http ...
- COM组件宏观认识
一直搞不清楚COM到底是个什么东西,记录一些个人感想,可能很多错误的,慢慢消化. 一.宏观认识: 1.COM(组件对象模型)是一种标准,规则,要求,即即于建筑设计指标要求. 2.语言无关性,因为是建立 ...