Codeforces 268D

来源:互联网 发布:淘宝新店能做什么活动 编辑:程序博客网 时间:2024/06/05 23:56

有一根柱子,每个点上可以插有且仅有一根棍子,棍子的方向有四种。
初始,可以选择任意方向往上爬,然后就只能按照原来的方向不停的往上爬。。。
dp[i][a1][a2][a3][a4]表示当前已经插前i跟棍子,第i跟棍子能否到达a1,其他三个方向的棍子与第i跟棍子的距离分别为a2,a3,a4

#include<cstdio>#include<iostream>#include<cstring>using namespace std;const int mod=1e9+9;typedef __int64 LL;LL dp[1010][2][31][31][31];void fm(LL &x){    if(x>mod)x-=mod;}int main(){    #ifdef DouBi    freopen("in.cpp","r",stdin);    #endif // DouBi    int n,h;while(scanf("%d%d",&n,&h)!=EOF){        memset(dp,0,sizeof(dp));        dp[0][0][0][0][0]=1;        LL val;        for(int i=0;i<n;i++){            for(int a=0;a<=1;a++){                for(int b=0;b<=h;b++){                    for(int c=0;c<=h;c++){                        for(int d=0;d<=h;d++)if(val=dp[i][a][b][c][d]){                            dp[i+1][a][b+1<h?b+1:h][c+1<h?c+1:h][d+1<h?d+1:h]+=dp[i][a][b][c][d];   fm(dp[i+1][a][b+1<h?b+1:h][c+1<h?c+1:h][d+1<h?d+1:h]);                            dp[i+1][b+1<=h?0:1][c+1<h?c+1:h][d+1<h?d+1:h][a?h:1]+=dp[i][a][b][c][d];fm(dp[i+1][b+1<=h?0:1][c+1<h?c+1:h][d+1<h?d+1:h][a?h:1]);                            dp[i+1][c+1<=h?0:1][d+1<h?d+1:h][a?h:1][b+1<h?b+1:h]+=dp[i][a][b][c][d];fm(dp[i+1][c+1<=h?0:1][d+1<h?d+1:h][a?h:1][b+1<h?b+1:h]);                            dp[i+1][d+1<=h?0:1][a?h:1][b+1<h?b+1:h][c+1<h?c+1:h]+=dp[i][a][b][c][d];fm(dp[i+1][d+1<=h?0:1][a?h:1][b+1<h?b+1:h][c+1<h?c+1:h]);                        }                    }                }            }        }        //printf("%I64d\n",dp[1][0][1][1][1]);        LL ans=0;        for(int a=0;a<=1;a++){            for(int b=0;b<=h;b++){                for(int c=0;c<=h;c++){                    for(int d=0;d<=h;d++){                        if(!a||b<h||c<h||d<h){                            //if(n==2&&dp[n][a][b][c][d])printf("%d %d %d %d %I64d\n",a,b,c,d,dp[n][a][b][c][d]);                            ans+=dp[n][a][b][c][d];fm(ans);                        }                    }                }            }        }        printf("%I64d\n",ans);    }    return 0;}
0 0
原创粉丝点击