Serie A champions:
To be in M row n Chocobo, there are some lattices you can plant trees that others cannot do. Not adjacent to the tree, I asked a number of different co-owned laws.
Analysis:
From the back to the next, the sub-problem extends to the parent problem, and when it is planted into a certain lattice, there is only the case of the n-1 lattice behind him and he has an effect on it. Therefore, the n lattice is encoded as a State s, indicating that the seed is finished (Domino that question is placed before. Note the difference, all feasible) the state of this n lattice. The parent problem is solved by a little Sub-problem, which is the idea of dynamic planning.
Code:
POJ 3254//sep9#include <iostream>using namespace std;const int Maxn=14;const int Mod=100000000;int land[maxN][ Maxn];int dp[2][1<<maxn];int M,n;int Main () {scanf ("%d%d", &m,&n); int i,j,used;for (i=0;i<m;++i) for ( J=0;J<N;++J) scanf ("%d", &land[i][j]); int *cur=dp[0],*nxt=dp[1];cur[0]=1;for (i=m-1;i>=0;--i) for (j=n-1;j >=0;--J) {for (used=0;used<1<<n;++used) {if (land[i][j]==0) {if (used>>j&1) nxt[used]=0;else{ Nxt[used]=cur[used];nxt[used]+=cur[used| ( 1<<J)];nxt[used]%=mod;}} Else{int res=0;if ((used>>j&1) && (used>> (j+1) &1)) {res=0;} else if (! ( used>>j&1) && (used>> (j+1) &1)) {res=cur[used];res+=cur[used| ( 1<<J)];} else if ((used>>j&1) &&! ( Used>> (j+1) &1) {res=cur[used& (~ (1<<J))];} else if (! ( USED>>J&1) &&! (Used>> (j+1) &1)) {res=cur[used];res+=cur[used| ( 1<<J)];} Nxt[used]=res%mod;}} Swap (CUR,NXT);} int sum=0;for (int i=0;i<1<<N;++i) {sum+=cur[i];sum%=mod;} printf ("%d", sum); return 0;}
POJ 3254 Corn Fields Country compression DP