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

 
 
 
正解:轮廓线动态规划
解题报告:
  轮廓线动态规划第一题,我觉得有必要好好总结一下。
  白书上的第六章第一题,尽管没有图的说明的情况下很难说清楚,但是我还是试图讲清楚。
  状态可以用二进制维护,首先我们对于每一个格子都可以表示是否被覆盖。而且不难想到,对于n×m的棋盘,只有上方和左方的共m个格子会产生影响,以前的必须已经被覆盖。
  所以我们考虑根据前m个格子的状态对现在进行决策,对于每个格子,显然可以不放(等于是等着右边的或者下面的来覆盖它),那么必须要满足的条件就是上方已经被覆盖,否则不合法;可以往左放,那么左边必须未被覆盖,且上方已经被覆盖;往上放,则只需上方未被覆盖即可。
  因为设计二进制表示状态,所以用位运算会很方便。
  另外,转移的话其实最优的不是枚举所有状态,而是类似于BFS的广搜转移,不再赘述。
 
 //It is made by jump~
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <ctime>
#include <vector>
#include <queue>
#include <map>
#include <set>
using namespace std;
typedef long long LL;
const int MAXN = ;
const int MAXS = (<<);
int n,m;
LL f[][MAXS]; inline void solve(){
memset(f,,sizeof(f));
int end=(<<m)-; int tag=;
f[][end]=;//注意初值的设定!!!
for(int i=;i<n;i++)
for(int j=;j<m;j++){
tag^=; memset(f[tag],,sizeof(f[tag]));
for(int k=;k<=end;k++) {
if((k<<)&(<<m)) f[tag][(k<<)^(<<m)]+=f[tag^][k];//这一个格子不放
if(i && ( !((k<<)&(<<m)) )) f[tag][(k<<)^]+=f[tag^][k];//往上放
if(j && (!(k&)) && ((k<<)&(<<m))) f[tag][(k<<)^^(<<m)]+=f[tag^][k];//往左放
}
}
printf("%lld\n",f[tag][end]);
} inline void work(){
while() {
scanf("%d%d",&n,&m); if(n== && m==) break;
if((n*m)%==) { printf("0\n"); continue; }
if(n<m) swap(n,m);
solve();
}
} int main()
{
work();
return ;
}

POJ2411 Mondriaan's Dream的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

  7. poj2411 Mondriaan's Dream (用1*2的矩形铺)

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

  8. POJ2411 Mondriaan's Dream 轮廓线dp

    第一道轮廓线dp,因为不会轮廓线dp我们在南京区域赛的时候没有拿到银,可见知识点的欠缺是我薄弱的环节. 题目就是要你用1*2的多米诺骨排填充一个大小n*m(n,m<=11)的棋盘,问填满它有多少 ...

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

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

随机推荐

  1. 第11章 Windows线程池(1)_传统的Windows线程池

    第11章 Windows线程池 11.1 传统的Windows线程池及API (1)线程池中的几种底层线程 ①可变数量的长任务线程:WT_EXECUTELONGFUNCTION ②Timer线程:调用 ...

  2. c#中结构体(struct)和类(class)的区别

    一.类与结构的示例比较: 结构示例: public struct Person { string Name; int height; int weight public bool overWeight ...

  3. 谈谈redis主从复制的重点

    Redis主从复制的配置十分简单,它可以使从服务器是主服务器的完全拷贝.下面是关于Redis主从复制的几点重要内容: Redis使用异步复制.但从Redis 2.8开始,从服务器会周期性的应答从复制流 ...

  4. css常用中文字体的英文名称写法

    我们知道网页中使用中文字体最好用其对应的英文名称,这样可以避免出现编码问题导致样式中的中文名称出现乱码,从而不识别.下面是网页中常用的中文字体所对应的英文名称.留着,不用翻资料了 中文 英文 宋体 S ...

  5. mybatis-config.xml详解

    <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE configuration PUBLIC ...

  6. Xcode7创建的项目添加启动图有问题?

    在Xcode7下创建的项目,由于某个原因,Xcode7添加启动图有点不一样.Xcode7与Xcode6不一样的地方在于:Xcode6的LaunchScreen.xib改成了LaunchScreen.s ...

  7. Python基础 - 获取N天前的日期

    获取今天前第N天的日期 from datetime import datetime from datetime import timedelta def get_date(days=N): retur ...

  8. Oracle 组织架构(转)

    原文地址:Oracle 组织架构 我们先来看一下实际生活中的集团组织架构. 下图是一个典型的投资集团组织架构. 集团在各个国家有独立的法人. 每个法人会负责若干个业务进行,比如石油开采,汽车制造,软件 ...

  9. 如何“刷leetcode”

    做题目的: 获得 offer 巩固算法与数据结构知识,将学到的东西用出来 如何做题: 根据章节与难度来做. 比如你学了 linked list,就去找到标签为 linked list 的题目,然后根据 ...

  10. IBatis.Net学习笔记六--再谈查询

    在IBatis.Net学习笔记五--常用的查询方式 中我提到了一些IBatis.Net中的查询,特别是配置文件的写法. 后来通过大家的讨论,特别是Anders Cui 的提醒,又发现了其他的多表查询的 ...