POJ 2411 Mondriaan ' s Dream

Source: Internet
Author: User

Given a n*m checkerboard, and a small rectangular 1*2, ask how many ways this large checkerboard is covered with this small rectangle.


DP[I][J]: How many ways, can make the status of line I is J

Dp[i][j]=sum{dp[i-1][k],k can be changed from legal to state J}

0: The location is free

1: The position is accounted for


Some people ask, each location is not 3 kinds of state? That is, the rectangle is not placed, a rectangle is placed horizontally, and a rectangle is put vertically


Of course, it is also possible to define the state in this way, using the three-input system.


With the three-in-one, the bit arithmetic and so on the handwriting is more troublesome ...


Or binary, then why is this definition possible?


Assuming that the position is placed at the left end of the rectangle at a position where the vertical position is the lower part of the rectangle


So, if I row J column is accounted for, then i+1 Row J column is not vertical?


If I row j column is not accounted for, then i+1 Row J column is only vertical?


With this in mind, the problem can be made by placing a rectangle into a position


If you still do not understand, look at my code to understand, if still do not understand ...


#include <iostream> #include <cstring>using namespace Std;long long dp[20][1<<11];int n,m;void DFS ( int S,int row,int Line,long long val) {int i,k;k=m-1;dp[row][line]+=val;for (i=s;i<k;i++) if ((line>>i&1) = = 0) if ((line>>i+1&1) ==0) DFS (i+2,row,line| ( 1<<i) | (1<<i+1), Val);} int main () {int I,j,k;while (cin>>n>>m) {if (n==0&&m==0) Break;memset (Dp,0,sizeof (DP));d FS ( 0,0,0,1); K=1<<m;for (i=1;i<n;i++) for (j=0;j<k;j++) DFS (0,i,k-1^j,dp[i-1][j]); Cout<<dp[n-1][k-1] <<endl;} return 0;}



POJ-2411

Mondriaan ' s Dream
Time Limit:3000MS Memory Limit:65536KB 64bit IO Format:%i64d &%i64u

Submit Status

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

Source

ULM Local 2000




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.