题目链接

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 2k2^k2k masks numbered from 0,1,⋯,0,1,\cdots,0,1,⋯, 2k−12^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 iii and jjj , then iii XNOR jjj must be positive. (two guests can wear the same mask). XNOR means ~(iii^jjj) and every number has kkk bits. (111 XNOR 1=11 = 11=1, 000 XNOR 0=10 = 10=1, 111 XNOR 0=00 = 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+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 TTT , the number of testcases; (T≤20)(T \le 20)(T≤20) .

Next TTT lines each contains two numbers, NNN and k(0<N,k≤1e6)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+7 .

样例输入复制

2
3 1
4 2

样例输出复制

2
84

题目来源

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

思路:题目意思,给你一个环让(环上有n个人),你在0到2^k-1这个范围内挑选数,使得任意相连的两个数字同或值为正,经过简单分析发现,第一个人有2^k种选法,第二个人有2^k-1种选法,第三个人有2^k-1种选法......但是最后一个人有2^k-2种选法,因为它和两个人相连。其实可以转换为着色问题。

所以有递推公式:

但是要注意如果n为奇数时,会少2^k种情况。

然后的话,递推和快速幂都能写。

代码:

#include<iostream>
#include<cstdio>
using namespace std;
typedef long long int ll;
ll mod=1e9+7,n,m=1,k,dp[1000005];
int main()
{int t;scanf("%d",&t);while(t--){m=1;scanf("%lld%lld",&n,&k);for(int i=1;i<=k;i++){m=m*2%mod;}dp[1]=0;dp[2]=m*(m-1)%mod;for(int i=3;i<=n;i++){dp[i]=((m-2)*dp[i-1]%mod+(m-1)*dp[i-2]%mod)%mod;}if(n&1) printf("%lld\n",(dp[n]+m)%mod);else printf("%lld\n",dp[n]);}
}

ACM-ICPC 2018 徐州赛区网络预赛 - A. Hard to prepare - (计数递归)相关推荐

  1. ACM-ICPC 2018 徐州赛区网络预赛 Features Track(STL二维map)

    Morgana is learning computer vision, and he likes cats, too. One day he wants to find the cat moveme ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 D. Easy Math

    Easy Math 问答问题反馈 只看题面 16.47% 1000ms 262144K Given a positive integers nn , Mobius function \mu(n)μ(n ...

  3. ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath

    ACM-ICPC 2018 徐州赛区网络预赛 D. EasyMath 做法: \[f(m,n) = \sum _{i=1}^{m} \mu(in) = \sum_{i=1}^{m}[gcd(i,n)= ...

  4. ACM-ICPC 2018 徐州赛区网络预赛G (单调队列)

    传送门 题面: There's a beach in the first quadrant. And from time to time, there are sea waves. A wave (  ...

  5. ACM-ICPC 2018 徐州赛区网络预赛 I. query 树状数组

    I. query 题目链接: Problem Description Given a permutation \(p\) of length \(n\), you are asked to answe ...

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

    BE, GE or NE 题意: 每一轮有三种操作, 加上a 减去b 或者 取负 当且仅当 a, b, c 不为0时,对应的操作有效; 给出一个上界和一个下界 大于等于上界就是 Good Ending ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 Morgana Net

    题意:Morgana Net 题解:把a矩阵每一位根据公式推出递推矩阵,然后用矩阵快速幂,比赛没想到啊,, #include<bits/stdc++.h> #define ll long ...

  8. Easy Math(ACM-ICPC 2018 徐州赛区网络预赛)(递归 + 杜教筛)

    Easy Math 推式子 ∑i=1mμ(in)∑i=1mμ(i×nd×d),d是n的一个质因子i,d互质项有(−∑i=1mμ(i×nd)),由于减去了多余的非互质项,所以加上,−∑i=1mμ(i×n ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 I. Characters with Hash

    注意几种情况,前导零是不要的:如果在开头的第一个值为个位数,那么占一位,如果个位数出现在中间,那么占两位,比如6就是06 #include <iostream> #include < ...

最新文章

  1. 使用easyBCD在Win10安装Ubuntu16.04LS安装双系统
  2. 查询Linux系统最后重启时间的三个方法
  3. java课程设计 成绩_java课程设计 学生成绩管理
  4. 老牌社交网站Friends Reunited宣布关闭
  5. C++——OOP(Object-Oriented Programming) vs. GP(Generic Programming)
  6. 提气!阿里平头哥三篇论文入选 ISCA
  7. 为什么说 Transformer 就是图神经网络?
  8. 工业和能源1994-2019年省级面板数据
  9. WebPlayer9电影整站系统第三方电影批量添加工具
  10. mac下Cornerstone显示日志问题 Cound not contact repository to read the latest log entries
  11. Linux python + selenium 以 kiosk模式打开Chrome浏览器 并 支持下载文件时询问下载路径
  12. Idea突然一直Indexing解决方法
  13. C++ switch怎么用
  14. 登录失败: 未知的用户名或错误密码。
  15. 屠龙传说世界【全自动】辅助脚本
  16. icinga用NSCA监控远程Linux服务器
  17. canvas绘图 echarts 基本使用
  18. fprintf函数的的用法
  19. 用英语计算机房造句子,机房造句
  20. SRE重案调查组 第二集 | 挖掘应用处理变慢的“真相”

热门文章

  1. ESP32 开发笔记(四)LVGL控件学习 Table 表格控件
  2. docker自学系列:docker挂载Nginx配置文件
  3. 【安全防护技术】防火墙技术
  4. 移动电商类微信:美肤汇、逛
  5. 手机长曝光怎么设置_挑战黑暗:怎样用手机拍出漂亮的长曝光照片?
  6. VR旅游,虚拟现实线上旅游优势|广州华锐互动
  7. Mac电脑想要快速返回桌面,简单几步即可搞定!
  8. 并发+JVM+Redis+MySQL+分布式+微服务+性能优化及阿里等大厂最新面试问答!
  9. linux 定时执行脚本发送邮件
  10. 成长一个不可逃脱的“劫难”