问题:

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
  • 到底是这么想到用01和11的,是不是有一类这样处理的题型呢?
  • 这种题一般都有很多优化,包括很多预处理;或者运算方式的优化,比如尽量用位运算;或者有多个check时优先check哪一个。
  • 这里实现了两种情况避免了暴力check(据说还有很多优化,但是代码肯定没我现在这么短了,嘻嘻哒):

α,上(x)下(y)不能同时为0,则一定是x|y==(1<<m)-1。这样就不需要一位一位check

β,上(x)下(y)同为1的连续个数需要为偶,即z=x&y中1必须成连续偶数次出现(表示竖着放的部分)。我们预先处理各种z,避免了每次都check。

  • 这里的写法应该是归类为插头DP还是轮廓线DP还是其他?不清楚,我已经混了,或者本来就是交叉没有明确界限的。还可以用轮廓DP的思想来解决,过几天再试一试。
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<cstring>
#include<cmath>
using namespace std;
long long dp[<<][];int n,m;
bool ok[<<];
void getok()
{
for(int i=;i<(<<);i++){
ok[i]=true;
for(int j=;j<;j++)
if(i&<<j){
int cnt=;
while(i&(<<(j+))) cnt++,j++;
if(cnt&){ok[i]=false ;break;}
}
}
}
bool check(int x,int y)
{
if((x|y)!=((<<m)-)) return false; //上下不能同时为0
return ok[x&y];//上下同时为1要满足连续时为偶。
}
int main()
{
int i,j,k;
getok();
while(~scanf("%d%d",&n,&m)){
if(n==&&m==) return ;
memset(dp,,sizeof(dp));
dp[(<<m)-][]=;
for(i=;i<=n;i++)
for(k=;k<(<<m);k++)
for(j=;j<(<<m);j++)
if(check(k,j)) dp[j][i]+=dp[k][i-];
printf("%lld\n",dp[(<<m)-][n]);
}
return ;
}

POJ2411Mondriaan's Dream(DP+状态压缩 or 插头DP)的更多相关文章

  1. POJ3254Corn Fields (状态压缩or插头DP)

    Description Farmer John has purchased a lush new rectangular pasture composed of M by N (1 ≤ M ≤ 12; ...

  2. HDU 4336 Card Collector (期望DP+状态压缩 或者 状态压缩+容斥)

    题意:有N(1<=N<=20)张卡片,每包中含有这些卡片的概率,每包至多一张卡片,可能没有卡片.求需要买多少包才能拿到所以的N张卡片,求次数的期望. 析:期望DP,是很容易看出来的,然后由 ...

  3. HDU 1074 Doing Homework (dp+状态压缩)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1074 题目大意:学生要完成各科作业, 给出各科老师给出交作业的期限和学生完成该科所需时间, 如果逾期一 ...

  4. hdu_4352_XHXJ's LIS(数位DP+状态压缩)

    题目连接:hdu_4352_XHXJ's LIS 题意:这题花大篇篇幅来介绍电子科大的一个传奇学姐,最后几句话才是题意,这题意思就是给你一个LL范围内的区间,问你在这个区间内最长递增子序列长度恰为K的 ...

  5. hdu 4352 数位dp + 状态压缩

    XHXJ's LIS Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total ...

  6. 【bzoj1076】[SCOI2008]奖励关 期望dp+状态压缩dp

    题目描述 你正在玩你最喜欢的电子游戏,并且刚刚进入一个奖励关.在这个奖励关里,系统将依次随机抛出k次宝物,每次你都可以选择吃或者不吃(必须在抛出下一个宝物之前做出选择,且现在决定不吃的宝物以后也不能再 ...

  7. hdu4336 Card Collector(概率DP,状态压缩)

    In your childhood, do you crazy for collecting the beautiful cards in the snacks? They said that, fo ...

  8. dp状态压缩

    dp状态压缩 动态规划本来就很抽象,状态的设定和状态的转移都不好把握,而状态压缩的动态规划解决的就是那种状态很多,不容易用一般的方法表示的动态规划问题,这个就更加的难于把握了.难点在于以下几个方面:状 ...

  9. 洛谷 1052 dp 状态压缩

    洛谷1052 dp 状态压缩 传送门 (https://www.luogu.org/problem/show?pid=1052#sub) 做完这道题之后,感觉涨了好多见识,以前做的好多状压题目都是将一 ...

随机推荐

  1. 前端基础之css样式(选择器)

    一.css概述 CSS是Cascading Style Sheets的简称,中文称为层叠样式表,对html标签的渲染和布局 CSS 规则由两个主要的部分构成:选择器,以及一条或多条声明. 例如 二.c ...

  2. Raspberry Pi开发之旅-发送邮件记录时间及IP

    由于我使用树莓派的场景大多数是在没有显示器.只用terminal连接它的情况下,所以,它的IP地址有时会在重启之后变掉(DHCP的),导致我无法通过terminal连接上它.然后我又要很麻烦地登录路由 ...

  3. 交叉编译Mesa,X11lib,Qt opengl

    记录Mesa配置文件如下: Mesa版本:Mesa-10.2.3 CC=/usr/local/arm-4.8.1/bin/arm-none-linux-gnueabi-gcc CXX=/usr/loc ...

  4. MySQL数据库基本操作(三)

    MySQL补充: mysql是关系型数据库,关系数据库,是建立在关系模型基础上的数据库,现实世界中的各种实体,以及实体之间的各种联系,均用关系模型(table)来表示.#关系模型就是指二维表格模型,因 ...

  5. nohup后台运行jar与关闭

    nohup 用途:LINUX命令用法,不挂断地运行命令.  语法:nohup Command [ Arg ... ] [ & ]  描述:nohup 命令运行由 Command 参数和任何相关 ...

  6. sqlserver的疑难杂症解析

    1.电脑修改ip后ssms通过ip访问失败 通过计算机名可以访问成功,但通过修改后的ip访问却失败了! 解决方法:打开Sql Server Configuration Manager -> SQ ...

  7. Java中初始变量默认值

    Java语言中有8种基本数据类型,基本情况汇总如下: 序号 数据类型 大小/位 封装类 默认值 可表示数据范围 1 byte(位) 8 Byte 0 -128~127 2 short(短整数) 16 ...

  8. App测试经验分享之登录注册

    要诀 另外自己总结了一些要诀,仅供参考: 1)快:快速操作,营造冲突的场景,例如加载过程中返回键交互,快速点击登录按钮,快速切换菜单项,快速多次上下拉刷新 2)变:手机横竖屏.手机切换语言.手机调整字 ...

  9. Overlay网络与物理网络的关系

    编者按:无论是云计算还是SDN都把注意力集中在数据中心网络的建设上,各种解决方案层出不穷,其中以VMware为代表的软件厂商提出Overlay网络方案后,为数据中心网络的发展提出了新的思路.那么Ove ...

  10. MySql基础学习-总纲