Luogu1879 [USACO06NOV]玉米田Corn Fields (状压DP)

曾经放弃的坑,都是坑

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#define R(a,b,c) for(register int  a = (b); a <= (c); ++ a)
#define nR(a,b,c) for(register int  a = (b); a >= (c); -- a)
#define Max(a,b) ((a) > (b) ? (a) : (b))
#define Min(a,b) ((a) < (b) ? (a) : (b))
#define Fill(a,b) memset(a, b, sizeof(a))
#define Abs(a) ((a) < 0 ? -(a) : (a))
#define Swap(a,b) a^=b^=a^=b
#define ll long long

#define ON_DEBUG

#ifdef ON_DEBUG

#define D_e_Line printf("

----------

")
#define D_e(x)  cout << #x << " = " << x << endl
#define Pause() system("pause")
#define FileOpen() freopen("inn.txt","r",stdin);

#else

#define D_e_Line ;
#define D_e(x)  ;
#define Pause() ;
#define FileOpen() ;

#endif

struct ios{
    template<typename ATP>ios& operator >> (ATP &x){
        x = 0; int f = 1; char c;
        for(c = getchar(); c < '0' || c > '9'; c = getchar()) if(c == '-')  f = -1;
        while(c >= '0' && c <= '9') x = x * 10 + (c ^ '0'), c = getchar();
        x*= f;
        return *this;
    }
}io;
using namespace std;

const int mod = 100000000;

int F[13];
int f[13][(1 << 12) + 7];
int g[(1 << 12) + 7];

int main(){
	int m, n;
	io >> n >> m;

    R(i,1,n){
        R(j,1,m){
            int x;
            io >> x;
            F[i] = (F[i] << 1) + x;
        }
    }

    R(i,0,(1 << m) - 1){
    	g[i] = (!(i & (i << 1))) && (!(i & (i >> 1)));
    }

    f[0][0] = 1;
    R(i,1,n){
        R(j,0,(1 << m) - 1){
            if(g[j] && ((j & F[i]) == j)) {
                R(k,0,(1 << m) - 1){
                    if((k & j) == 0){
                        f[i][j] = (f[i][j] + f[i - 1][k]) % mod;
                    }
                }
            }
        }
    }

    int ans = 0;
    R(i,0,(1 << m) - 1){
        ans = (ans + f[n][i]) % mod;
    }
    
    printf("%d
", ans);
    return 0;
}

原文地址:https://www.cnblogs.com/bingoyes/p/11234615.html