bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排

链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1725

题意:中文题。

分析:裸的状态压缩DP。

代码:

#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<bitset>
#include<math.h>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
const int N=1000010;
const int MAX=151;
const int mod=100000000;
const int MOD1=100000007;
const int MOD2=100000009;
const double EPS=0.00000001;
typedef long long ll;
const ll MOD=1000000009;
const ll INF=10000000010;
typedef double db;
typedef unsigned long long ull;
int f[15],q[5000],dp[15][5000];
int pd(int x) {
    for (int i=0;i<=12;i++)
    if ((x&(1<<i))&&(x&(1<<(i+1)))) return 0;
    return 1;
}
int main()
{
    int i,j,k,n,m,x,ans=0;
    scanf("%d%d", &n, &m);
    for (i=1;i<=n;i++) {
        f[i]=0;
        for (j=1;j<=m;j++){
            scanf("%d", &x);
            if (x) f[i]|=1<<(j-1);
        }
    }
    memset(dp,0,sizeof(dp));
    dp[0][0]=1;f[0]=0;
    for (i=0;i<(1<<m);i++) q[i]=pd(i);
    for (i=1;i<=n;i++)
        for (j=0;j<(1<<m);j++)
        if (q[j]&&(j&f[i])==j) {
            for (k=0;k<(1<<m);k++)
            if ((k&f[i-1])==k&&q[k]&&(k&j)==0) dp[i][j]=(dp[i][j]+dp[i-1][k])%mod;
        }
    for (i=0;i<(1<<m);i++) ans=(ans+dp[n][i])%mod;
    printf("%d\n", (ans+mod)%mod);
    return 0;
}


你可能感兴趣的:(bzoj1725: [Usaco2006 Nov]Corn Fields牧场的安排)