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. [LeetCode] 415 Add Strings && 67 Add Binary && 43 Multiply Strings

    这些题目是高精度加法和高精度乘法相关的,复习了一下就做了,没想到难住自己的是C++里面string的用法. 原题地址: 415 Add Strings:https://leetcode.com/pro ...

  2. Tensorflow之卷积神经网络(CNN)

    前馈神经网络的弊端 前一篇文章介绍过MNIST,是采用的前馈神经网络的结构,这种结构有一个很大的弊端,就是提供的样本必须面面俱到,否则就容易出现预测失败.如下图: 同样是在一个图片中找圆形,如果左边为 ...

  3. HDFS源码分析之NameNode(3)————RpcServer

    NameNodeRpcServer implements NamenodeProtocols NameNode支持核心即NameNodeRpcServer 实现ClientProtocol  支持客户 ...

  4. 51 nod 1495 中国好区间 奇葩卡时间题 700ms 卡O(n*log(n)), 思路:O(n)尺取法

    题目: 这个题目竟然叫中国好区间,要不要脸.欸,不得不说还蛮顺口的,哈哈哈. 首先我们有一个数组a.可以递推得来,O(n)时间复杂度. 定义left(有效区间的左端点),bigger(有效区间中大于等 ...

  5. 【笔记】php常用函数

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

  6. 自适应 Tab 宽度可以滑动文字逐渐变色的 TabLayout(仿今日头条顶部导航)

    TabLayout相信大家都用过,2015年Google大会上发布了新的Android Support Design库里面包含了很多新的控件,其中就包含TabLayout,它可以配合ViewPager ...

  7. ASP.NET没有魔法——第一个ASP.NET应用《MyBlog》

    创建一个ASP.NET MVC应用程序 在之前文章中介绍了ASP.NET中提供了3个开发动态网页的框架,分别是Web Form.MVC以及Web Pages,也大概介绍了它们的特点. 其中MVC对于其 ...

  8. HDU3605 Escape

    思想:缩点+sap Max,t还可以缩小,优化,高数课写的,有点丑,暂时懒得改. #include<cstdio> #include<cstdlib> #include< ...

  9. Jquery 多选全选/取消 选项卡切换 获取选中的值

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. 【原创】自用css reset

    自己工作中常用的reset,和一些设置,实际用时会根据网站页面进行增删. /* Common style */html{ overflow-y:scroll; overflow-x:auto;}bod ...