poj 3254 Corn Fields
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
int rem[15],state[1000],dp[15][1000];
int m,n,most;
int find_all_state()
{
most=1;
int line=1<<n;
for(int i=0;i<line;++i)
{
if((i&(i<<1))==0)
{
state[most]=i;
++most;
}
}
--most;
return 0;
}
int main()
{
while(scanf("%d%d",&m,&n)!=EOF)
{
memset(rem,0,sizeof(rem));
find_all_state();
for(int i=1;i<=m;++i)
{
int tem;
for(int j=1;j<=n;++j)
{
scanf("%d",&tem);
if(tem==0)
rem[i]=rem[i]|(1<<(n-j));
}
}
memset(dp,0,sizeof(dp));
for(int i=1;i<=most;++i)
{
if((state[i]&rem[1])==0)
{
dp[1][i]=1;
}
}
for(int i=2;i<=m;++i)
{
for(int k=1;k<=most;++k)
{
if((state[k]&rem[i])==0)
{
for(int j=1;j<=most;++j)
{
if(((state[j]&rem[i-1])==0)&&((state[j]&state[k])==0))
{
dp[i][k]=(dp[i][k]+dp[i-1][j])%100000000;
}
}
}
}
}
int ans=0;
for(int i=1;i<=most;++i)
{
ans=(ans+dp[m][i])%100000000;
}
cout<<ans<<endl;
}
return 0;
}
#include<stdio.h>
#include<string.h>
#include<iostream>
using namespace std;
#define ls rt<<1
#define rs (rt<<1)+1
#define PI acos(-1)
#define eps 1e-8
#define ll long long
#define fuck(x) cout<<#x<<" "<<x<<endl;
typedef pair<int,int> pii;
const int inf=2e9;
const int maxn=1e6+10;
int d[4][2]={1,0,-1,0,0,1,0,-1};
//int lowbit(int x){return x&-x;}
//void add(int x,int v){while(x<=n)bit[x]+=v,x+=lowbit(x);}
//int sum(int x){int ans=0;while(x>=1) ans+=bit[x],x-=lowbit(x);return ans;}
inline ll read() {
ll s = 0,w = 1;
char ch = getchar();
while(!isdigit(ch)) {
if(ch == '-') w = -1;
ch = getchar();
}
while(isdigit(ch))
s = s * 10 + ch - '0',ch = getchar();
return s * w;
}
inline void write(ll x) {
if(x < 0)
putchar('-'), x = -x;
if(x > 9)
write(x / 10);
putchar(x % 10 + '0');
}
const int mod=1e8;
int m,n,tot,state[32000],cur[20],dp[15][32000];
bool fit(int x,int k){
return !(state[x]&cur[k]);
}
void init(){
int sum=1<<n;
for(int i=0;i<sum;i++){
if(!(i&(i<<1)))
state[++tot]=i;
}
}
int main(){
int ans=0;
m=read();
n=read();
init();
for(int i=1;i<=m;i++)
for(int j=1;j<=n;j++)
{
int tmp;
tmp=read();
if(!tmp)
cur[i]|=(1<<(n-j));
}
for(int i=1;i<=tot;i++)
if(fit(i,1))
dp[1][i]=1;
for(int i=2;i<=m;i++)
for(int j=1;j<=tot;j++)
{
if(!fit(j,i)) continue;
for(int k=1;k<=tot;k++)
{
if(!fit(k,i-1)||state[j]&state[k]) continue;
dp[i][j]+=dp[i-1][k];
dp[i][j]%=mod;
}
}
for(int j=1;j<=tot;j++)
ans+=dp[m][j],ans%=mod;
write(ans);
return 0;
}