ACM-ICPC 2018 徐州赛区网络预赛 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^k2
k
masks numbered from 0,1,\cdots,0,1,⋯, 2^k - 12
k
−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,k1e6)k(0<N,k1e6) k ( 0 < N , k ≤ 1 e 6 ) k ( 0 < N , k ≤ 1 e 6 )
.

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
它相当于有 2k 2 k 的状态,每个状态就是由1,0,组成的一个串,同或为0的情况只有一种就是全不相等的情况,那么就可以转化成有 2k 2 k 种颜色,每一个颜色都与上一个颜色不同是差不多的。但是n是奇数的时候少了 2k 2 k 种可能,因为涂色问题不把全部相同算为一种,那么加上去就好了。

#include<bits/stdc++.h>
using namespace std;
#define LL long long
const LL mod =1e9+7;
LL sw(LL a,LL b){
    LL ans=1;
    while(b){
        if(b&1)ans=ans*a%mod;
        b>>=1;a=a*a%mod;
    }return ans;
}


int main(){
    int t;scanf("%d",&t);
    while(t--){
        LL n,k;scanf("%lld%lld",&n,&k);
        LL J=(sw(2ll,k)-1ll+mod)%mod;

        LL ans=(sw(-1,n)*J%mod+sw(J,n))%mod;

        if(n%2)ans=(ans+sw(2,k))%mod;

        printf("%lld\n",ans);
    }
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值