Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 8974 | Accepted: 5187 |
Description

Expert as he was in this material, he saw at a glance that he'll need a computer to calculate the number of ways to fill the large rectangle whose dimensions were integer values, as well. Help him, so that his dream won't turn into a nightmare!
Input
Output

Sample Input
1 2 1 3 1 4 2 2 2 3 2 4 2 11 4 11 0 0
Sample Output
1 0 1 2 3 5 144 51205
Source
/* * POJ 2411 * 状态压缩DP * 一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? * 横着的定义为11,竖着的定义为01, * 然后按行DP,两行状态相或要全为1.两行相与要没有连续的1的个数是奇数个 */ #include <iostream> #include <string.h> #include <stdio.h> #include <algorithm> using namespace std; bool check(int s)//判断s有没有奇数个连续的1 { int ret=0; while(s) { if(s&1)ret++; else { if(ret&1)return false; ret=0; } s>>=1; } if(ret&1)return false; return true; } long long dp[12][2050]; int main() { int n,m; while(scanf("%d%d",&n,&m)==2) { if(n==0 && m==0)break; int tot=(1<<m); memset(dp,0,sizeof(dp)); for(int i=0;i<tot;i++) if(check(i)) dp[1][i]=1; for(int i=1;i<n;i++) for(int j=0;j<tot;j++) if(dp[i][j]!=0) { for(int k=0;k<tot;k++) if( (j|k)==tot-1 && check(j&k) ) dp[i+1][k]+=dp[i][j]; } printf("%I64d\n",dp[n][tot-1]); } return 0; }