2018 徐州网络赛A

  •  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 - 12k1, 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)(T20) .

Next TT lines each contains two numbers, NN and k(0<N, k \le 1e6)k(0<N,k1e6) .

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

题目来源

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

思路:

设计dp(i,j) (j=0,1,2)   分别表示到第 i 个位置的三种情况。

dp(i,0)  表示第 i 个位置与第一个位置相等的时候。

dp(i,1)  表示第 i 个位置与第一个位置异或取反相等的情况。

dp(i,2)  表示第 i 个位置除前两种情况外的情况。

易得状态转移方程:

  f[i][0]=f[i-1][0]+f[i-1][2];
  f[i][1]=f[i-1][1]+f[i-1][2])%mod;
  f[i][2]=f[i-1][0]*(2^k-2)+f[i-1][1]*(2^k-2)+f[i-1][2]*(2^k-3);

代码如下:

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int maxn=1e6+10;
ll Pow_mod(ll a,ll n){
    ll res=1ll;
    while(n){
        if(n&1) res=res*a%mod;
        a=a*a%mod;
        n>>=1;
    }return res;
}
ll f[maxn][3],d,d2,d3;

int main(){
    int _,n,k;
    // freopen("in.txt","r",stdin);
    for (scanf("%d",&_); _; _--){
        scanf("%d%d",&n,&k);
        d=Pow_mod(2,k);
        d2=(d-2+mod)%mod;
        d3=(d-3+mod)%mod;
        f[0][0]=d,f[0][1]=f[0][2]=0;
        for (int i=1; i<n; ++i){
            f[i][0]=(f[i-1][0]+f[i-1][2])%mod;
            f[i][1]=(f[i-1][1]+f[i-1][2])%mod;
            f[i][2]=(f[i-1][0]*d2%mod+f[i-1][1]*d2%mod+f[i-1][2]*d3%mod)%mod;
        }
        printf("%lld\n",(f[n-1][0]+f[n-1][2])%mod);
    }
    return 0;
}
View Code

 

posted @ 2018-09-12 23:18  Acerkoo  阅读(231)  评论(0编辑  收藏  举报