Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 16771 | Accepted: 9683 |
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
#include<cstring>
#include<cstdio>
using namespace std;
#define LL long long
LL dp[2][2050];
LL ans[15][15];
bool check(int x,int i)
{ return x&(1<<i); }
bool comp(int A,int B,int N)
{
int i=0,j,k;
while(i<N){
if(!check(A,i)){
if(!check(B,i)) return 0;
i++;
}
else{
if(!check(B,i)) i++;
else {
if(i==N-1||!check(A,i+1)||!(check(A,i+1)&&check(B,i+1))) return 0;
else i+=2;
}
}
}
return 1;
}
void solve(int N,int M)
{
if(ans[N][M]+1) {printf("%lld\n",ans[N][M]);return;}
memset(dp,0,sizeof(dp));
dp[0][(1<<N)-1]=1;
int cur=1;
for(int i=1;i<=M;++i){
for(int j=0;j<(1<<N);++j){dp[cur][j]=0;
for(int k=0;k<(1<<N);++k){
if(comp(j,k,N)) dp[cur][j]+=dp[cur^1][k];
}
}
cur^=1;
}
ans[N][M]=ans[M][N]=dp[cur^1][(1<<N)-1];
printf("%lld\n",dp[cur^1][(1<<N)-1]);
}
int main()
{
memset(ans,-1,sizeof(ans));
int N,M,i,j,k,l;
while(scanf("%d%d",&N,&M)!=EOF&&(N||M)){
if(N*M%2==1) {puts("0");continue;}
if(N>M) {swap(N,M);}
solve(N,M); //M行N列
}
return 0;
}