zoukankan      html  css  js  c++  java
  • 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 - 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 徐州赛区网络预赛

     

     

     

    #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=1;
        a%=MOD;
        while(b){
            if(b&1) ans=ans*a%MOD;
            b>>=1;
            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[1] = qMod(2ll,k);
            ll temp1 = (dp[1]-1+MOD)%MOD;
            ll temp2 = (dp[1]-2+MOD)%MOD;
            dp[2] = dp[1]*temp1%MOD;
            for(i=3;i<=n;i++){
                dp[i]=(dp[i-2]*temp1%MOD+(dp[i-1]-dp[1]+MOD)%MOD*temp2%MOD)%MOD;
            }
            printf("%lld
    ",dp[n]);
        }
        return 0;
    }
  • 相关阅读:
    【BZOJ】2453: 维护队列【BZOJ】2120: 数颜色 二分+分块(暴力能A)
    【转】使用json-lib进行Java和JSON之间的转换
    【转】MySQL索引和查询优化
    【转】SQL常用的语句和函数
    【转】MySQL日期时间函数大全
    VMare中安装“功能增强工具”,实现CentOS5.5与win7host共享文件夹的创建
    MyEclipse中消除frame引起的“the file XXX can not be found.Please check the location and try again.”的错误
    由于SSH配置文件的不匹配,导致的Permission denied (publickey)及其解决方法。
    复选框的多选获取值
    echart环形图制作及出现的一些问题总结
  • 原文地址:https://www.cnblogs.com/yzm10/p/9614217.html
Copyright © 2011-2022 走看看