POJ 3254 Corn Fields

状态压缩DP

#include<cstdio>
#include<cstring>

const int MOD=100000000;
int dp[15][5000];
int mapp[15][15];

int main()
{
    int m,n;
    while(~scanf("%d%d",&m,&n))
    {
        for(int i=1; i<=m; i++)
            for(int j=1; j<=n; j++)
            {
                int tmp;
                scanf("%d",&tmp);
                tmp=!tmp;
                mapp[i][j]=tmp;
            }
        memset(dp,0,sizeof(dp));
        dp[0][0]=1;
        for(int i=1; i<=m; i++)
        {
            int aaa=0;
            for(int s=1; s<n; s++)
            {
                aaa+=mapp[i][s];
                aaa<<=1;
            }
            aaa+=mapp[i][n];
            for(int j=0; j<=(1<<(n))-1; j++)
            {
                if(j&(j>>1))continue;
                if(j&(aaa))continue;
                for(int k=0; k<=(1<<(n))-1; k++)
                {
                    if(j&k)continue;
                    dp[i-1][k]=dp[i-1][k]%MOD;
                    dp[i][j]=(dp[i][j]+dp[i-1][k])%MOD;
                }
            }
        }
        int maxit=0;
        for(int i=0; i<=(1<<n)-1; i++)
        {
            dp[m][i]=dp[m][i]%MOD;
            maxit=(maxit+dp[m][i])%MOD;
        }
        printf("%d\n",maxit);
    }

    return 0;
}

 

posted @ 2015-08-08 21:32  Fighting_Heart  阅读(217)  评论(0编辑  收藏  举报