标签:des style blog http color strong
线上题目:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 6936 | Accepted: 3697 |
Description
Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; 1 ≤ N ≤ 12) square parcels. He wants to grow some yummy corn for the cows on a number of squares. Regrettably, some of the squares are infertile and can‘t be planted. Canny FJ knows that the cows dislike eating close to each other, so when choosing which squares to plant, he avoids choosing squares that are adjacent; no two chosen squares share an edge. He has not yet made the final choice as to which squares to plant.
Being a very open-minded man, Farmer John wants to consider all possible options for how to choose the squares for planting. He is so open-minded that he considers choosing no squares as a valid option! Please help Farmer John determine the number of ways he can choose the squares to plant.
Input
Output
Sample Input
2 3 1 1 1 0 1 0
Sample Output
9
Hint
1 2 3
4
1 #include <cstdio> 2 #include <cstring> 3 #include <iostream> 4 #define MAX 2048 5 #define LL long long 6 #define MOD 100000000 7 using namespace std; 8 9 LL dp[15][MAX]; 10 LL in[MAX],state[MAX]; 11 int m,n,cnt; 12 13 void init(){ 14 cnt=0; 15 for(int i=0;i<(1<<n);i++) if( (i&(i<<1)) == 0 ) state[cnt++]=i; 16 } 17 18 int main() 19 { 20 //freopen("data.txt","r",stdin); 21 while(scanf("%d %d",&m,&n)!=EOF){ 22 init(); 23 for(int i=0;i<m;i++){ 24 int o; 25 in[i]=0; 26 for(int j=0;j<n;j++){ 27 scanf("%d",&o); 28 in[i]=in[i]|(o<<j); 29 } 30 } 31 memset(dp,0,sizeof(dp)); 32 for(int i=0;i<cnt;i++){ 33 if( (in[0]&state[i]) == state[i] ) dp[0][i]=1; 34 } 35 for(int i=1;i<m;i++){ 36 for(int j=0;j<cnt;j++){ 37 if( (in[i]&state[j]) == state[j] ) 38 for(int k=0;k<cnt;k++){ 39 if( (state[j]&state[k]) == 0) dp[i][j]=(dp[i][j]+dp[i-1][k])%MOD; 40 } 41 } 42 } 43 LL sum=0; 44 for(int i=0;i<cnt;i++) sum=(sum+dp[m-1][i])%MOD; 45 cout<<sum<<endl; 46 } 47 return 0; 48 }
POJ - 3254 - Corn Fields,布布扣,bubuko.com
标签:des style blog http color strong
原文地址:http://www.cnblogs.com/sineatos/p/3845465.html