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. android 知识点收集

    1.  计算时间流逝请使用SystemClock.elapsedRealtime... currentTimeMillis会受系统时钟影响  //未验证 2.  android app私有文件的目录 ...

  2. finder怎么才能找到library

    右键Finder——前往目录 输入~/Library

  3. DRDB报错------0: Failure: (119) No valid meta-data signature found.

    一. 错误 drbdadm create-md datadrbdadm up data  <--启动时报错 [root@data-- ~]# drbdadm up data : Failure: ...

  4. ace布置小作业: 制作一个简单的电话号码归属地查询软件:JSON解析和Volly发送get请求

    大概就这个样子 用到JSON解析和Volly发送Get请求两个知识点 关于Volly的用法请看我的这篇: http://www.cnblogs.com/AceIsSunshineRain/p/5177 ...

  5. dxut.h(29): fatal error C1083: Cannot open include file: 'dxsdkver.h': No such file or directory

    从网上download一个三维演示模型的软件编译发现报找不到dxsdkver.h文件,网上查阅这是MS的DirectX sdk中的库文件,于是先download DirectX SDK 安装之后,配置 ...

  6. GCD工作单元

    #import <UIKit/UIKit.h> @interface ViewController : UIViewController @property (weak,nonatomic ...

  7. windows编程原理

    这里在学网络编程时遇到了讲解windows的编程,稍微整理一下windows编程原理,顺便复习一下. 首先,理解Windows 程序运行原理:Windows应用程序,操作系统,计算机硬件之间的相互关系 ...

  8. 关于页面滚动值scrollTop在FireFox与Chrome浏览器间的兼容问题

    需求 最近在做博客的目录功能,发现一个在现代浏览器间的一个bug,或是称之为差异,即页面滚动值(scrollTop)的获取与设定. 在此之前先说一下关于页面元素的坐标获取,这张图的经典性不必再提. 实 ...

  9. 全解┃OpenStack Newton发布,23家中国企业上榜(转载)

    (转载自Openstack中文社区) 陈, 翔 2016-10-8 | 暂无评论 美国奥斯汀时间10月6日(北京时间6日24点),OpenStack Newton版本正式发布,在可扩展性.可靠性和用户 ...

  10. mac版beyond compare 4 中对比class文件

    http://www.scootersoftware.com/download.php?zz=moreformats 这个网址中没有mac版本的class文件对比的file format.只能自己造了 ...