POJ 3411 Mondriaan's Dream 銆愮姸鍘婦p銆?By cellur925

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了POJ 3411 Mondriaan's Dream 銆愮姸鍘婦p銆?By cellur925相关的知识,希望对你有一定的参考价值。

鏍囩锛?a href='http://www.mamicode.com/so/1/name' title='name'>name   wing   paper   閫氳繃   mina   sed   material   seve   numbers   

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his 鈥榯oilet series鈥?(where he had to use his toilet paper to draw on, for all of his paper was filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and height 1 in varying ways. 
鎶€鏈垎浜浘鐗? src=

Expert as he was in this material, he saw at a glance that he鈥榣l 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鈥榯 turn into a nightmare!

Input

The input contains several test cases. Each test case is made up of two integer numbers: the height h and the width w of the large rectangle. Input is terminated by h=w=0. Otherwise, 1<=h,w<=11.
Output
鎶€鏈垎浜浘鐗? src=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


鎶€鏈垎浜浘鐗? src=

锛堜竴鍙ヨ瘽棰樻剰锛?/p>

 

鏈鐨勬暟鎹寖鍥村緢灏忥紝nm鍧囦负11锛岃繖鎻愮ず鎴戜滑鍙互鐢ㄧ姸鍘嬨€傛垜浠彲浠ラ澶勭悊鍑烘墍鏈夋í鏀鹃鐗岀殑鐘舵€侊紝鍗宠〃绀轰负涓€涓簩杩涘埗涓诧紝濡傛灉涓?锛屽垯璇佹槑杩欓噷鏈夐鐗岋紝涓?锛屽垯璇佹槑杩欓噷娌℃湁楠ㄧ墝銆?/p>

 1 bool check(int x)
 2 {
 3     bool ok=1;
 4     for(int i=0;i<n;i++)
 5     {
 6         if(x&(1<<i)) ok=ok^1;
 7         //褰撳墠浣嶄负1锛岃涓嬩负1鐨勪釜鏁帮紝鏈€缁堝繀椤讳袱涓ょ浉閭讳笖涓暟涓哄伓鏁?
 8         if((!(x&(1<<i)))&&!ok) return 0;
 9     }
10     if(ok) return 1;
11     else return 0;
12 }

鎴戜滑鑰冭檻璁捐涓€涓姸鎬侊紝f[i][j]琛ㄧず褰撳墠鍦ㄧi琛岋紝褰撳墠琛岀姸鎬佷负j鐨勬柟妗堟暟锛屾垜浠殑杞Щ鐩爣鏄痜[m][(1<<n)-1]锛堝嵆鍦ㄦ渶鍚庝竴琛岋紝姣忎釜鍦版柟閮借濉弧锛?/p>

鍒欏彲浠ュ啓鍑鸿浆绉绘柟绋嬶細f[i][j]=+f[i-1][bin[k]^j^fAKe]锛坘鏋氫妇涓婁竴琛岀殑鐘舵€侊紝婊¤冻鏉′欢k鏄痡鐨勫瓙闆嗭紝涔熷氨鏄兘杞Щ鍒板綋鍓嶇姸鎬佺殑涓婁竴鐘舵€侊級涓ゆ寮傛垨鏄湪姹傝兘杞Щ鍒板綋鍓嶇姸鎬佺殑涓婁竴鐘舵€併€傛寜瀛﹂暱鐨勮瘽璇村氨鏄細閭d箞鎴戜滑瀵逛簬姣忎釜鐘舵€侊紝濡傛灉鎴戜滑鐭ラ亾浜嗗畠鍝簺鏄í鏀剧殑锛岄偅涔堟垜浠篃灏卞彲浠ユ帹鍑哄畠涓婁竴琛岀殑鐘舵€侊紝鍥犱负褰撳墠琛屽繀椤昏鎶婁笂涓€琛岃ˉ婊°€?/p>

娉ㄦ剰缁嗚妭锛氬紑long long锛圵A浜嗗ソ鍑犳锛?/p>

code

鎶€鏈垎浜浘鐗? id=
 1 #include<cstdio>
 2 #include<algorithm>
 3 #include<cstring>
 4 
 5 using namespace std;
 6 typedef long long ll;
 7 
 8 int n,m,cnt;
 9 int bin[3000];
10 ll f[12][2050];
11 
12 bool check(int x)
13 {
14     bool ok=1;
15     for(int i=0;i<n;i++)
16     {
17         if(x&(1<<i)) ok=ok^1;
18         if((!(x&(1<<i)))&&!ok) return 0;
19     }
20     if(ok) return 1;
21     else return 0;
22 }
23 
24 void init()
25 {
26     memset(f,0,sizeof(f));
27     memset(bin,0,sizeof(bin));
28     cnt=0;
29 }
30 
31 int main()
32 {
33 
34     while(scanf("%d%d",&n,&m))
35     {
36         if(n==0) break;
37         int fAKe=(1<<n)-1;
38         for(int i=0;i<=fAKe;i++)
39              if(check(i)) bin[++cnt]=i;
40          for(int i=1;i<=cnt;i++) f[1][bin[i]]=1;
41          for(int i=2;i<=m;i++)
42           for(int j=0;j<=fAKe;j++)
43            for(int k=1;k<=cnt;k++)
44             if((bin[k]|j)==j) f[i][j]+=f[i-1][bin[k]^j^fAKe];
45          printf("%lld
",f[m][fAKe]);
46         init();
47     }
48     return 0;
49 }
View Code

 

娉細鎴戜滑杩欓噷璇寸殑瀛愰泦姒傚康锛屼妇涓緥瀛愶細

{1锛?锛?}涓轰竴闆嗗悎锛屽垯浜岃繘鍒剁1浣嶆垨绗笁浣嶆垨绗?浣嶄笂涓?鐨勬墍鏈夋暟绉颁负瀹冪殑瀛愰泦銆傜敱浜庢垨杩愮畻婊¤冻鈥滄湁涓€涓?鍗充负1鈥濓紝鍒欐垜浠€氳繃鎴栬繍绠楀彲浠ユ潵妫€鏌ユ槸鍚﹀瓨鍦ㄥ瓙闆嗗叧绯汇€?/p>





以上是关于POJ 3411 Mondriaan's Dream 銆愮姸鍘婦p銆?By cellur925的主要内容,如果未能解决你的问题,请参考以下文章

POJ2411 Mondriaan's Dream

POJ 2411Mondriaan's Dream(状压dp)

poj2411 Mondriaan's Dream状压DP

POJ 2411Mondriaan's Dream

POJ 2411 Mondriaan's Dream

[poj P2411] Mondriaan's Dream