POJ 2411 Mondriaan ' s Dream

Source: Internet
Author: User

Topic Link http://poj.org/problem?id=2411

Mondriaan ' s Dream
Time Limit: 3000MS Memory Limit: 65536K
Total Submissions: 12445 Accepted: 7261

Description

Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, after producing the drawings in his ' Toilet series ' (where he had to use his toilet paper to draw on, for all O F His paper is filled with squares and rectangles), he dreamt of filling a large rectangle with small rectangles of width 2 and Height 1 in varying ways.

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

Input

The input contains several test cases. Each test case was made up of the 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

For each test case, output the number of different ways the given rectangle can is 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 21 31 42 22 32 42 114 110 0

Sample Output

10123514451205

Test instructions: give you a piece of h*w rectangle, to use the small rectangular block of 1*2 to fill it, can be vertical, can also be placed sideways. Ask at most how many kinds of situations.
Reference: http://www.cnblogs.com/jackge/archive/2013/05/24/3097205.html
Analysis: Because to be paved, you can know if the given h*w if an odd number of times, must be paved dissatisfaction, such as 1 3.
If an even number is the case.
Set DP[I][J] To line I, the maximum number of methods when the state is J.
Because the last is to be covered.
Consider this lattice of column K in a row in three cases.
1. Is the first of the horizontal, then the K+1 column is the second grid in the horizontal, so the two positions are set to 1 1.
2. Vertical, and the column of the previous row of the grid form a piece. Then set this position to 1, the previous line corresponding to the position of 0.
3. Vertical, and the next line of this column of the grid form a piece. So set this position 0, the corresponding position of the previous line is 1.
In such a case, there will be no conflict of circumstances.
The first line requires special consideration because there is no previous line before the first row, so there is only one case if you want to put it vertically.
Reference to other people's code, is written with Dfs, very concise, learning.
1#include <iostream>2#include <cstring>3#include <cstdio>4#include <string>5#include <algorithm>6 using namespacestd;7 inth, W;8 Long Longdp[ A][(1<< A)+1];9 voidInitintStaintPOS) {Ten     if(pos = =W) { Onedp[1][sta] =1; A         return; -     } -     if(POS +1<= W) {//can be placed vertically, and if it is vertical, it must be 0, because the first row does not have a previous row.  theInit (sta<<1, pos+1); -     } -     if(POS +2<= W) {//you can put it sideways. -Init (sta<<2|3, pos+2); +     } - } + voidDfsintIintNowsintPresintPOS) { A     if(pos = =W) { atDp[i][nows] + = dp[i-1][pres];  -         return; -     } -     if(POS +1<= W) {//put it upright. -DFS (i, nows<<1|1, pres<<1, pos+1);//this line and the previous line become a vertical block.  -DFS (i, nows<<1, pres<<1|1, pos+1);//this line and the next line become a vertical block.  in     }  -     if(POS +2<=W) { toDFS (i, nows<<2|3, pres<<2|3, pos+2); +     }  - } the intMain () { *      while(SCANF ("%d%d", &h, &w) && (H +W)) { $         if((h*w)%2){Panax Notoginsengprintf"0\n"); -             Continue; the         } +Memset (DP,0,sizeof(DP)); AInit0,0); the          for(inti =2; I <= H; i++) DFS (i,0,0,0); +cout<<dp[h][(1&LT;&LT;W)-1]<<Endl; -     } $      $     return 0; -}

POJ 2411 Mondriaan ' s Dream

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.