Corn Fields
1 #include <iostream> 2 #include <cstdio> 3 #include <cstring> 4 using namespace std; 5 const int Ni = 13; 6 const int mod = 100000000; 7 int map[Ni][Ni]; 8 int dp[Ni][1<<12]; 9 int n,m,add; 10 void dfs(int i,int s0,int s,int cur) 11 { 12 if(cur>=m) {dp[i][s]=(dp[i][s]+add)%mod;return;} 13 dfs(i,s0,s,cur+1); 14 if(cur<m&&!(s0&1<<cur)&&map[i][cur]&&!(s&3<<cur)) 15 dfs(i,s0,s|1<<cur,cur+2); 16 } 17 int main() 18 { 19 int i,j,ans; 20 memset(map,0,sizeof(map)); 21 while(~scanf("%d%d",&n,&m)) 22 { 23 for(i=1;i<=n;i++) 24 for(j=0;j<m;j++) 25 { 26 scanf("%d",&map[i][j]); 27 } 28 int rt=1<<m; 29 memset(dp,0,sizeof(dp)); 30 add=1; 31 dfs(1,0,0,0); 32 for(i=2;i<=n;i++) 33 { 34 for(j=0;j<rt;j++) if(dp[i-1][j]) 35 { 36 add=dp[i-1][j]; 37 dfs(i,j,0,0); 38 } 39 } 40 ans=0; 41 for(j=0;j<rt;j++) 42 ans=(ans+dp[n][j])%mod; 43 printf("%d\n",ans); 44 } 45 return 0; 46 }