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. JS设计模式(二) 惰性模式

    惰性模式:减少代码每次执行时的重复性判断,通过重新定义对象来避免原对象中的分支判断,提高网站性能. 例如针对不同浏览器的事件注册方法: var AddEvent = function(dom, typ ...

  2. 【转】TCP/IP协议中TCP和UDP的区别

    TCP协议与UDP协议的区别    首先咱们弄清楚,TCP协议和UCP协议与TCP/IP协议的联系,很多人犯糊涂了,一直都是说TCP/IP协议与UDP协议的区别,我觉得这是没有从本质上弄清楚网络通信! ...

  3. Milk Patterns poj3261(后缀数组)

    Milk Patterns Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 9274   Accepted: 4173 Cas ...

  4. 一.把传统服务做成dubbo分布式服务架构的步骤

    1.把传统服务按照一定原则(根据项目的业务逻辑和场景)拆分成多个服务(主要服务是服务提供者和服务消费者,服务提供者或服务消费者的公共部分也可以拆分成其他服务,如公共DAO.公共工具类.公共实体,公共w ...

  5. 简易RPC框架-过滤器机制

    *:first-child { margin-top: 0 !important; } body > *:last-child { margin-bottom: 0 !important; } ...

  6. python爬取煎蛋网图片

    ``` py2版本: #-*- coding:utf-8 -*-#from __future__ import unicode_literimport urllib,urllib2,timeimpor ...

  7. ubuntu环境下lnmp环境搭建(1)之Mysql

    1. vm下安装Ubuntu 1)下载镜像ubuntu-15.04-desktop-amd64.iso http://yunpan.cn/cF5dwV6zw33ef 访问密码 ecba(个人分享在36 ...

  8. UpdatePanel控件的使用和局部刷新

    http://www.cnblogs.com/baiefjg/archive/2009/06/14/1502813.html

  9. thinking in java 随笔

    初始化顺序 在一个类里,初始化的顺序是由变量在类内的定义顺序决定的.即使变量定义大量遍布于方法定义的中间,那些变量仍会在调用任何方法之前得到初始化--甚至在构建器调用之前.例如: class Tag ...

  10. 吾八哥学Python(四):了解Python基础语法(下)

    咱们接着上篇的语法学习,继续了解学习Python基础语法. 数据类型大体上把Python中的数据类型分为如下几类:Number(数字),String(字符串).List(列表).Dictionary( ...