百题计划-4 codeforces 652 div2 D. TediousLee 找规律

https://codeforces.com/contest/1369/problem/D

n<=2e6,所以只要找递推式就可以了,不需要找快速幂

/**




*/
#include<bits/stdc++.h>

using namespace std;

typedef long long ll;
const int maxn=2000100;
const int INF=(1LL<<30);
const ll MOD=1e9+7;

ll f[maxn][2],n;

void init(){
    memset(f,0,sizeof(f));
    f[3][0]=0;f[3][1]=1;
    f[4][0]=f[4][1]=1;
    f[5][0]=3;f[5][1]=2;
    for(int i=6;i<maxn;i++){
        f[i][1]=((f[i-2][0]*2)%MOD+f[i-1][0]+1)%MOD;
        f[i][0]=((max(f[i-2][0],f[i-2][1])*2)%MOD+max(f[i-1][0],f[i-1][1]))%MOD;
    }
}

int main(){
    int T;cin>>T;
    init();
    while(T--){
        cin>>n;
        cout<<(max(f[n][0],f[n][1])*4LL)%MOD<<endl;
    }
    return 0;
}
View Code

 

posted on 2020-08-21 19:40  KEZ  阅读(107)  评论(0)    收藏  举报

导航