hdu 2047递推

来源:互联网 发布:nginx 访问图片 404 编辑:程序博客网 时间:2024/05/17 03:49

     A[N]表示以E或者F结尾的情况下的方案数,B[N]表示以O结尾的情况下的方案数,F[N]=3*A[N-1]+2*B[N-1]

     同时,A[N]=2*B[N-1]+2*A[N-1],B[N-1]=A[N-1]

AC代码:

#include<cstdio>typedef long long LL;const int maxn=40+5;LL ans[maxn];void solve(){    LL a=2,b=1;    ans[1]=3;    for(int i=2;i<40;++i){        LL t1=a,t2=b;        ans[i]=3*a+2*b;        a=2*(t1+t2);        b=t1;    }}int main(){    solve();    int n;    while(scanf("%d",&n)==1){        printf("%lld\n",ans[n]);    }    return 0;}

如有不当之处欢迎指出!

0 0