任意门:https://nanti.jisuanke.com/t/31453

A.Hard to prepare

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

题意概括:

有 N 个客人 2^K 顶帽子, 每顶帽子编号为 1 ~ 2^K, N 个客人围成一个圈, 要求相邻两个客人的帽子编号(K位二进制)同或不为0。

解题思路:

第一步:推可能存在的方案数, 这个举几个栗子就可以发现两个帽子不满足条件的情况只有一种,那就是相邻编号互为取反数(二进制取反)。

第二步:

找规律找递推关系。

画一下样例图解会发现 排除 第 1 个 和 第 N 个互为取反数的情况,因为后一个只有一个编号不满足条件的, 所以可能性有 2^K * (2^K-1) ^ ( N-2 ) * (2^K-2);

很明显这种情况是不完整的,因为有 ~① == ~③ 的情况。

所以我们接下来要做的就是找到 ~① == ~③ 的情况有多少(也就是① == ③的情况啦)

把这部分漏的补上去就是完整的结果了。

这部分漏的怎么找呢,递推回 N-2 个 按照之前那条规律计算 ( 2^K * (2^K-1) ^ ( N-2-2 ) * (2^K-2);)

然后可能又出现上述情况,继续递推回去,一直算算算...算到只有两个客户或者一个客户的时候就可以停止啦

Tip:

当然这道题也可以先算出  2^K * (2^K-1) ^ ( N-3 ) ;

然后这部分没有考虑  ① != ③ 的情况, 所以我们找出 ① != ③ 这种情况有多少种。

用总的减去这部分不满足条件的也是答案。

参考:https://blog.csdn.net/qq_36424540/article/details/82586694

我们假设有  颗珠子,   我们不考虑开头 对末尾的限制, 只是考虑  对 的限制,答案就是 , 这些情况是多了的,多了   这种情况, 然后我们再来计算这种情况有多少?

现在的条件 是 已知 第一个是 , 最后一个是, 问一共有多少种方案。

我们先考虑简单的情况 ,假设一共只有 3个 珠子  ,我们第一个是A,第三个是, 那么第二个只能选 个。 所以多了的就是 中情况。

然后推广一下, 我们考虑   这个位置是 ,那么   这个位置 只有    种情况, 所以我们减掉  种情况,可是这个情况仍然 少了   这个位置上 是 的情况,所以我们还得加上 现在确定 第一个位置是  A ,第  个位置是  的情况, 所以一直 .......   , 结束的位置在哪里呢?

结束的位置也就是 最早出现 的位置,也就是  第三个位置,所以 我们可以变得位置计算到 第二个也就是  可以了

AC code(第一种):

 #include <bits/stdc++.h>
#define INF 0x3f3f3f3f
#define LL long long
#define mod 1000000007
using namespace std;
const int MAXN = 1e6+;
LL a[MAXN];
LL N, K; LL pow(LL x, LL n) //快速幂
{
LL res = ;
while(n){
if(n&) res = res*x%mod;
x = x*x%mod;
n >>= ;
}
return res;
} void init() //初始化求2^k
{
a[] = ;
for(int i = ; i < MAXN; i++)
a[i] = (a[i-]*2LL)%mod;
} LL check(LL n, LL k) //递推求解
{
if(n == ) return a[k]%mod;
else if(n == ) return (a[k]*(a[k]-))%mod;
LL res;
res = ( (a[k]*pow((a[k]-), n-)%mod) * (max(a[k]-2LL, 0LL)))%mod;
res = ( res + check(n-, k)%mod)%mod;
return res;
} int main()
{
int T_case;
init();
scanf("%d", &T_case);
while(T_case--){
scanf("%lld%lld", &N, &K);
printf("%lld\n", check(N, K));
}
return ;
}

ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 【规律递推】的更多相关文章

  1. ACM-ICPC 2018 徐州赛区网络预赛 A Hard to prepare(递推)

    https://nanti.jisuanke.com/t/31453 题目 有n个格子拉成一个环,给你k,你能使用任意个数的0 ~ 2^k - 1,规定操作 i XNOR j 为~(i  ^  j), ...

  2. ACM-ICPC 2018 徐州赛区网络预赛 A Hard to prepare

    https://nanti.jisuanke.com/t/31453 题目大意: 有n个人坐成一圈,然后有\(2^k\)种颜色可以分发给每个人,每个人可以收到相同的颜色,但是相邻两个人的颜色标号同或不 ...

  3. ACM-ICPC 2018 徐州赛区网络预赛A Hard to prepare(DP)题解

    题目链接 题意:有n个格子拉成一个环,给你k,你能使用任意个数的0 ~ 2^k - 1,规定操作 i XNOR j 为~(i  ^  j),要求相邻的格子的元素的XNOR为正数,问你有几种排法,答案取 ...

  4. ACM-ICPC 2018 徐州赛区网络预赛 A. Hard to prepare (组合数学,递归)

    A. Hard to prepare After Incident, a feast is usually held in Hakurei Shrine. This time Reimu asked ...

  5. ACM-ICPC 2018 徐州赛区网络预赛(8/11)

    ACM-ICPC 2018 徐州赛区网络预赛 A.Hard to prepare 枚举第一个选的,接下来的那个不能取前一个的取反 \(DP[i][0]\)表示选和第一个相同的 \(DP[i][1]\) ...

  6. ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心)

    ACM-ICPC 2018 徐州赛区网络预赛 G. Trace (思维,贪心) Trace 问答问题反馈 只看题面 35.78% 1000ms 262144K There's a beach in t ...

  7. ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer (最大生成树+LCA求节点距离)

    ACM-ICPC 2018 徐州赛区网络预赛 J. Maze Designer J. Maze Designer After the long vacation, the maze designer ...

  8. 计蒜客 1460.Ryuji doesn't want to study-树状数组 or 线段树 (ACM-ICPC 2018 徐州赛区网络预赛 H)

    H.Ryuji doesn't want to study 27.34% 1000ms 262144K   Ryuji is not a good student, and he doesn't wa ...

  9. ACM-ICPC 2018 徐州赛区网络预赛 B(dp || 博弈(未完成)

    传送门 题面: In a world where ordinary people cannot reach, a boy named "Koutarou" and a girl n ...

随机推荐

  1. oracle 错误实例分析(ORA-01078)

    01,问题描述 心血来潮想看一下启动数据库的alert log.然后把数据库给关闭了,同时也在监听日志文件    下面可谓是详细的描述了整个关机过程,也看到了无数的error [root@node1 ...

  2. jumpserver 安装详解

    一,下载软件 下载前安装依赖软件 yum install -y epel-release                        yum -y install git python-pip my ...

  3. CAD 卸载工具,完美彻底清除干净cad各种残留注册表和文件

    是不是遇到MAYA/CAD/3DSMAX/INVENTOR安装失败?AUTODESK系列软件着实令人头疼,MAYA/CAD/3DSMAX/INVENTOR安装失败之后不能完全卸载!!!(比如maya, ...

  4. JS及Dom练习 | 模态对话框及复选框操作

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  5. (转)IPC相关的命令

    IPC相关的命令 原文:http://www.cnblogs.com/jjzd/p/6773090.html 进程间通信概述 进程间通信有如下的目的: 1.数据传输,一个进程需要将它的数据发送给另一个 ...

  6. (转) Linux Shell经典实例解析

    原文:http://blog.csdn.net/yonggeit/article/details/72779955 该篇博客作为对之前Linux Shell常用技巧和高级技巧系列博客的总结,将以Ora ...

  7. oracle 查询及删除表中重复数据

    create table test1( id number, name varchar2(20) ); ,'jack'); ,'jack'); ,'peter'); ,'red'); insert i ...

  8. Unity5.x发布IOS项目Xcode8免签证调试发布教程

    https://www.jianshu.com/p/b0fb49fbcc14 最近尝试发布一下IOS项目,发现现在发布已经简单很多了,不需要开发者账户也能简单快捷进行真机调试. 调试: 1.准备工作 ...

  9. python中时间对象生成及时间格式的转换

    1.将字符串的时间转换为时间戳 方法: a = "2013-10-10 23:40:00" 将其转换为时间数组 import time timeArray = time.strpt ...

  10. 中文输入法无法在 QtCreator(Linux) 中输入汉字

    中文输入法无法在 QtCreator(Linux) 中输入汉字 环境 system: Deepin 15.7 Qt Creator 4.7.0 (GCC 5.3.1) 解决方法 下载 fcitx-qt ...