zoukankan      html  css  js  c++  java
  • Codeforces Round #652 (Div. 2) D

    #include<map>
    #include<queue>
    #include<time.h>
    #include<limits.h>
    #include<cmath>
    #include<ostream>
    #include<iterator>
    #include<set>
    #include<stack>
    #include<cstdio>
    #include<cstring>
    #include<iostream>
    #include<algorithm>
    using namespace std;
    #define rep_1(i,m,n) for(int i=m;i<=n;i++)
    #define mem(st) memset(st,0,sizeof st)
    int read()
    {
        int res=0,ch,flag=0;
        if((ch=getchar())=='-')             //判断正负
            flag=1;
        else if(ch>='0'&&ch<='9')           //得到完整的数
            res=ch-'0';
        while((ch=getchar())>='0'&&ch<='9')
            res=res*10+ch-'0';
        return flag?-res:res;
    }
    typedef long long ll;
    typedef pair<int,int> pii;
    typedef unsigned long long ull;
    typedef pair<double,double> pdd;
    const int inf = 0x3f3f3f3f;
    const int maxn=2000005; 
    ll dp[maxn],x[maxn];
    const ll mod=1000000007;
    int main()
    {
        dp[3]=4;
        dp[4]=4;
        x[3]=1;
        x[4]=0;
        //对于level i
        //可以看成 根节点 连着 两个 level i-2 和一个 level i-1
        //然后画图 发现 i%3==0 时 需要加上根节点的鸡爪 
        for(int i=5; i<=2000000; i++)
        {
            dp[i]=2*dp[i-2]+dp[i-1];
            if(x[i-2]==0&&x[i-1]==0) dp[i]+=4,x[i]=1;
            dp[i]%=mod;
        }
        int q=read();
        while(q--)
        {
            int x=read();
            printf("%lld
    ",dp[x]);
        }
        return 0;
    }
  • 相关阅读:
    「JXOI2018」游戏
    「CTSC2018」假面
    CodeForces
    CodeForces
    [Lydsy1710月赛] 小B的数字
    OpenJ_Bailian
    [SDOI2010] 地精部落
    CodeForces
    CodeForces
    [NOI2009] 管道取珠
  • 原文地址:https://www.cnblogs.com/QingyuYYYYY/p/13190105.html
Copyright © 2011-2022 走看看