codeforces 268D Wall Bars (dp)

来源:互联网 发布:网络综合布线施工要求 编辑:程序博客网 时间:2024/06/05 02:10

题意:

给出一个n层的楼,每层有四个方向,可以建一个bar,两个层之间的bar要小于h才能可达。求满足至少能达到

n-h+1~n方案数!

题解:

莫名其妙的题目,dp[i][j]前i个高度这个高度建的方向为j的方案书,j=0表示没建。奇葩的题目,这样的状态方程是错的。

正解更吓人 dp[i][a][b][c][d]表示i高度a方向是否可达(a=0、1),并且距b方向的bar的距离为b,距c方向的bar的距离为c,距d方向的bar的距离为d。每次旋转换方向!


#include<iostream>#include<math.h>#include<stdio.h>#include<algorithm>#include<string.h>#include<vector>#include<map>using namespace std;typedef long long ll;const int oo=0x3f3f3f3f;const ll OO=1LL<<61;const ll MOD=1000000009;const int maxn=1000+5;int dp[maxn][2][33][33][33];int val;void inc(int &a){    if((a+=val)>=MOD)a-=MOD;}int main(){    int n,h;    while(scanf("%d %d",&n,&h)!=EOF)    {        memset(dp,0,sizeof dp);        dp[0][0][0][0][0]=1;        for(int i=1;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-1][a][b][c][d]){                                inc(dp[i][a<1?0:1][b<h?b+1:h][c<h?c+1:h][d<h?d+1:h]);                                inc(dp[i][b<h?0:1][c<h?c+1:h][d<h?d+1:h][a<1?a+1:h]);                                inc(dp[i][c<h?0:1][d<h?d+1:h][a<1?a+1:h][b<h?b+1:h]);                                inc(dp[i][d<h?0:1][a<1?a+1:h][b<h?b+1:h][c<h?c+1:h]);                            }        int 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((val=dp[n][a][b][c][d])&&(a<1||b<h||c<h||d<h)){                        inc(ans);                        }        cout<<ans<<endl;    }    return 0;}/***/



0 0
原创粉丝点击