标签:des style blog http color os io java ar
Description

Input
Output
For each test case, output the number of different ways the given rectangle can be filled with small rectangles of size 2 times 1. Assume the given large rectangle is oriented, i.e. count symmetrical tilings multiple times.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
压缩时,0是横放或竖放的下半部分,1是竖放的上半部分。
注意:
要用long long;
1 #include<iostream> 2 #include<cstring> 3 #include<cstdlib> 4 #include<cstdio> 5 #include<algorithm> 6 #include<cmath> 7 #include<queue> 8 #include<map> 9 #include<vector> 10 #include<set> 11 12 #define N 1130 13 #define M 15 14 #define inf 1000000007 15 #define mod 1000000007 16 #define mod2 100000000 17 #define ll long long 18 #define maxi(a,b) (a)>(b)? (a) : (b) 19 #define mini(a,b) (a)<(b)? (a) : (b) 20 21 using namespace std; 22 23 int h,w; 24 ll dp[15][ (1<<11)+10 ]; 25 int s[15]; 26 ll ans; 27 28 void ini() 29 { 30 memset(dp,0,sizeof(dp)); 31 ans=0; 32 } 33 34 int check(int o) 35 { 36 int cou=0; 37 //int flag=1; 38 int j=0; 39 for(j=0;j<w;j++){ 40 s[j]=o%2; 41 o/=2; 42 } 43 j=0; 44 while(j<w) 45 { 46 while(s[j]==1 && j<w) j++; 47 cou=0; 48 while(s[j]==0 && j<w){ 49 cou++;j++; 50 } 51 if(cou%2==1) return 0; 52 } 53 if(cou%2==1) return 0; 54 return 1; 55 } 56 57 void solve() 58 { 59 int o,i,p,te; 60 if(h*w%2==1) return; 61 for(o=0;o<(1<<w);o++){ 62 if( check(o)==0 ) continue; 63 dp[1][o]=1; 64 // printf(" o=%d\n",o); 65 } 66 67 for(i=2;i<h;i++){ 68 for(o=0;o<(1<<w);o++){ 69 for(p=0;p<(1<<w);p++){ 70 if( (p&o)!=0 ) continue; 71 te=o | p; 72 if( check(te)==0 ) continue; 73 dp[i][o]+=dp[i-1][p]; 74 } 75 } 76 } 77 78 for(p=0;p<(1<<w);p++){ 79 if( check(p)==0 ) continue; 80 dp[h][0]+=dp[h-1][p]; 81 } 82 ans=dp[h][0]; 83 } 84 85 void out() 86 { 87 printf("%I64d\n",ans); 88 } 89 90 int main() 91 { 92 // freopen("data.in","r",stdin); 93 //freopen("data.out","w",stdout); 94 //scanf("%d",&T); 95 // for(int cnt=1;cnt<=T;cnt++) 96 // while(T--) 97 while(scanf("%d%d",&h,&w)!=EOF) 98 { 99 if(h==0 && w==0) break; 100 ini(); 101 solve(); 102 out(); 103 } 104 return 0; 105 }
标签:des style blog http color os io java ar
原文地址:http://www.cnblogs.com/njczy2010/p/3959155.html