Mondriaan’s Dream

Time Limit: 3000MS Memory Limit: 65536K

Total Submissions: 18903 Accepted: 10779

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 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.

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

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

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

code:

//By Menteur_Hxy
#include<cstdio>
#include<iostream>
#include<cstdlib>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<ctime>
#include<queue>
#include<vector>
using namespace std; const int MAX=500010;
const int INF=0x3f3f3f3f; int n,m,cnt;
long long f[12][1<<11];
bool pd[1<<11]; int main() {
while(scanf("%d %d",&n,&m) && n) {
for(int i=0;i<1<<m;i++) {
int x=i;
bool cnt=0,has=0;
for(int j=0;j<m;j++,x>>=1) {
if(x&1) has |=cnt,cnt=0;
else cnt ^=1;
}
pd[i]=has|cnt?0:1;
}
f[0][0]=1;
for(int i=1;i<=n;i++)
for(int j=0;j<1<<m;j++){
f[i][j]=0;
for(int k=0;k<1<<m;k++)
if(!(j&k) && pd[j|k])
f[i][j]+=f[i-1][k];
}
printf("%lld\n",f[n][0]);
}
return 0;
}

[poj 2411]Mondriaan's Dream (状压dp)的更多相关文章

  1. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  2. Poj 2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...

  3. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  4. POJ 2411 Mondriaan'sDream(状压DP)

    题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...

  5. [poj2411] Mondriaan's Dream (状压DP)

    状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...

  6. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

  7. POJ - 2411 Mondriaan's Dream(轮廓线dp)

    Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...

  8. poj 2411 Mondriaan's Dream(状态压缩dP)

    题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...

  9. poj 2411 Mondriaan's Dream (轮廓线DP)

    题意:有一个n*m的棋盘,要求用1*2的骨牌来覆盖满它,有多少种方案?(n<12,m<12) 思路: 由于n和m都比较小,可以用轮廓线,就是维护最后边所需要的几个状态,然后进行DP.这里需 ...

  10. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

随机推荐

  1. 【ACM】hdu_1004_Let the Balloon Rise

    Let the Balloon Rise Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. Storm工作流程 vs. Spark Stream

    看的这个学习课程: http://study.163.com/course/courseLearn.htm?courseId=1002887002#/learn/video?lessonId=1003 ...

  3. 关于Java特种兵下冊

    <Java特种兵 下冊>这本书一直没出.至上冊出版近1年以来,每周会有非常多小伙伴发私信或邮件问起我下冊出版的事情,纵使眼下有非常多无奈,小胖还是初步决定准备写下冊. 下冊内容(下冊的内容 ...

  4. [深入理解Android卷一全文-第七章]深入理解Audio系统

    由于<深入理解Android 卷一>和<深入理解Android卷二>不再出版,而知识的传播不应该由于纸质媒介的问题而中断,所以我将在CSDN博客中全文转发这两本书的全部内容. ...

  5. luogu3386 【模板】 二分图匹配

    基本概念:二分图有两种节点:X节点和Y节点.如果X和Y可以匹配, 则X与Y连着一条边.每个X节点最多只能匹配一个Y节点,同时每个Y节点最多只能匹配一个X节点.最大匹配便是最多的匹配数. 交错路径:交错 ...

  6. POJ3463 Sightseeing

    题目大意:求两点间最短路与长度为最短路长度+1的路径的条数之和. 方法1:最短路径+DP 首先求出ST间最短路径,然后根据递归式记忆化搜索(因此还要构造反向图). 我们知道到达终点的路径长度最长为ma ...

  7. day63-webservice 10.jquery的调用webservice小练习

    客户端是采用jquery方式来做调用.但是这种调用,因为jquery这种调用你就得有消息体.我们得先拿到这种消息体.PersonService这个服务类有两个方法. http://localhost: ...

  8. Codeforces Round #512 (Div. 2) D.Vasya and Triangle 数学

    题面 题意:给你n,m,k,在你在(0,0)到(n,m)的矩形内,选3个格点(x,y都是整数),使得三角形面积为n*m/k,不能找到则输出-1 题解:由毕克定理知道,格点多边形的面积必为1/2的整数倍 ...

  9. MyEclipse设置默认注释的格式

    首先选菜单windows-->preferenceJava-->Code Style-->Code Templates code-->new Java files 然后选中点编 ...

  10. [] == ![]为什么是true

    我们先来考虑这个问题,console.log([] == false)会打印什么呢? 答案是true.为什么呢? 首先,因为当"=="号两边其中一个是布尔值的话,先把它转换为数字( ...