Mondriaan's Dream
Time Limit: 3000MS   Memory Limit: 65536K
Total Submissions: 15295   Accepted: 8820

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

Source

/*
已经给了时间看题解了,正式练习一道题三天之内不准再看题解!
*/
#include <iostream>
#include <stdio.h>
#include <string.h>
#define N (1<<12)+5
#define M 12
/*
用1表示当前小方格填满了,0表示没填满,初始化第一行的状态然后递推到最后一行
*/
using namespace std;
long long dp[M][N];//dp[i][j]表示第i行j种状态做多有多少种排列方式
int n,m;
bool check(int x)//判断是不是有连续个奇数个1;当有连续奇数个1的时候那么这一行横着放的肯定是不会填满的
{
int s=;
while(x)
{
if(x&)s++;
else
{
if(s&)return false;
s=;
}
x>>=;
}
if(s&)return false;
return true;
}
int main()
{
///for(int i=0;i<30;i++)
// cout<<"i="<<i<<" "<<check(i)<<endl;
//cout<<endl;
//freopen("in.txt","r",stdin);
//freopen("out.txt","w",stdout);
while(scanf("%d%d",&n,&m)!=EOF&&n&&m)
{
if((n*m)%)//如果乘积是奇数的话是肯定铺不满的
{
printf("0\n");
continue;
}
if(n<m)//这里做一个剪枝,使m永远是小的那个,能减少不少循环的次数
{
int tmp=n;
n=m;
m=tmp;
}
int tol=(<<m);
memset(dp,,sizeof dp);
for(int i=;i<tol;i++)//初始第一行的状态
if(check(i))
dp[][i]=;
for(int i=;i<n;i++)//由i行推出i+1行
for(int j=;j<tol;j++)//枚举上一个状态
if(dp[i][j]!=)//上一个状态为零没计算意义
{
for(int k=;k<tol;k++)
{
if( (j|k)==tol- && check(j&k) )//这一步很精妙,(j|k)==tol-1保证了肯定能填满上一行,check(j&k)保证了这一行中横着放的小木块绝对能填满
dp[i+][k]+=dp[i][j];
}
}
printf("%lld\n",dp[n][tol-]);
}
return ;
}

POJ2411 Mondriaan's Dream(状态压缩)的更多相关文章

  1. POJ2411 - Mondriaan's Dream(状态压缩DP)

    题目大意 给定一个N*M大小的地板,要求你用1*2大小的砖块把地板铺满,问你有多少种方案? 题解 刚开始时看的是挑战程序设计竞赛上的关于铺砖块问题的讲解,研究一两天楞是没明白它代码是怎么写的,智商捉急 ...

  2. 【poj2411】Mondriaan's Dream 状态压缩dp

    AC传送门:http://vjudge.net/problem/POJ-2411 [题目大意] 有一个W行H列的广场,需要用1*2小砖铺盖,小砖之间互相不能重叠,问有多少种不同的铺法? [题解] 对于 ...

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

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

  4. poj2411 Mondriaan's Dream【状压DP】

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 20822   Accepted: 117 ...

  5. [Poj2411]Mondriaan's Dream(状压dp)(插头dp)

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 18096   Accepted: 103 ...

  6. POJ1185 炮兵阵地 和 POJ2411 Mondriaan's Dream

    炮兵阵地 Language:Default 炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 34008 Accepted ...

  7. poj2411 Mondriaan's Dream (轮廓线dp、状压dp)

    Mondriaan's Dream Time Limit: 3000MS   Memory Limit: 65536K Total Submissions: 17203   Accepted: 991 ...

  8. poj 2411 Mondriaan's Dream_状态压缩dp

    题意:给我们1*2的骨牌,问我们一个n*m的棋盘有多少种放满的方案. 思路: 状态压缩不懂看,http://blog.csdn.net/neng18/article/details/18425765 ...

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

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

随机推荐

  1. AngularJS [ 快速入门教程 ]

      前  序 S    N AngularJS是什么? 我想既然大家查找AngularJS就证明大家多多少少对AngularJS都会有了解. AngularJS就是,使用JavaScript编写的客户 ...

  2. Excel开发之旅

    开发环境:Microsoft Visual Studio 2015,Office 2013 开发语言:C# 1.创建工程:文件à新建à项目,选择office 外接程序àExcel 2013和2016 ...

  3. jenkins~集群分发功能和职责处理

    jenkins的多节点集群 在进行自动化部署时,你可以按着它们的项目类型去进行分别部署,这样即可以达到负载均衡,又可以达到一种职责的明确,比如像java的项目你可以使用linux服务来进行部署(拉代码 ...

  4. 【JVM命令系列】jstat

    命令基本概述 Jstat是JDK自带的一个轻量级小工具.全称"Java Virtual Machine statistics monitoring tool",它位于java的bi ...

  5. Windows下 如何添加开机启动项

    Windows XP,Windows 7: 开始 ----> 所有程序 ----> 启动, 右键打开"启动"这个文件夹, 把想开机自动启动的软件快捷方式拖进去即可. ( ...

  6. 【笔记】php常用函数

    phpusleep() 函数延迟代码执行若干微秒.unpack() 函数从二进制字符串对数据进行解包.uniqid() 函数基于以微秒计的当前时间,生成一个唯一的 ID.time_sleep_unti ...

  7. 一个“.java”文件中是否可以包含多个类(不是内部类)?有什么限制?

    可以,若这个类的修饰符是public则,其类名须与文件名相同.

  8. bzoj1027 [HNOI2004]打鼹鼠

    [HNOI2004]打鼹鼠 2014年5月2日2,8605 Description 鼹鼠是一种很喜欢挖洞的动物,但每过一定的时间,它还是喜欢把头探出到地面上来透透气的.根据这个特点阿Q编写了一个打鼹鼠 ...

  9. java猜数字(实验任务五)

    1.程序设计思想: 先随机获取1-100之内的数字i: 在建立让用户输入数字的对话框,然后判断猜高了.低了还是猜对了: 用循环直到用户猜对了. 2.程序流程图: 3.源代码: package 实验任务 ...

  10. PHP通过访客来路获取搜索关键词的方法

    <?php class keyword{ public function getKeyword($referer){ if(strpos($referer,"http://www.ba ...