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. Fix "Missing Scripts"

    一.Missing Scripts(脚本引用丢失) 请看下面的两张图的Warn(脚本引用丢失),在某些情况下我们会遇到这个警告. 二.解决办法 参考资料 http://unitygems.com/la ...

  2. C#FTP登入

    FtpWebRequest reqFTP; try { // 根据uri创建FtpWebRequest对象 reqFTP = (FtpWebRequest)FtpWebRequest.Create(n ...

  3. eval() 函数

    eval() 函数可计算某个字符串,并执行其中的的 JavaScript 代码. var str = '12+45*45'; alert(eval(str))//计算结果 还有一个重要作用可以把字符串 ...

  4. 02SpringMvc_springmvc快速入门小案例(XML版本)

    这篇文章中,我们要写一个入门案例,去整体了解整个SpringMVC. 先给出整个项目的结构图:

  5. 【转】【C#】【Thread】Interlocked 轻量级锁

    为什么说它是轻量级呢?因为它仅对整形数据(即int类型,long也行)进行同步. 具体使用如下表: Interlocked.Increment(ref value) 数值加一(原子性操作) Inter ...

  6. IC系统组成概论

    IC系统是什么? 对算法工程师来说,IC系统是完成特定功能的硬件.对架构设计师来说,IC系统包括控制,运算,存储部分.电路设计工程师来说,IC系统是加法器,乘法器,与非门,运算放大器,开关电容等的搭配 ...

  7. SSH公钥认证+优化

    一 ssh公钥认证流程: sshclinet机器:产生公私钥(公钥相当于一把锁) sshclient:将公钥发给sshserver(抛出锁子) sshclinet去连sshserver不需要密钥   ...

  8. Table AdvanceTable针对表内行禁用multipleSelection , singleSelection

    OATableBean table = (OATableBean)webBean.findChildRecursive("LineTable"); table.setInserta ...

  9. Spring MVC实现文件下载

     下载文件① 下载文件需要将byte数组还原成文件. 首先使用mybatis将数据库中的byte数组查出来,指定文件名(包括格式).然后使用OutputStream将文件输入 @RequestMapp ...

  10. [CareerCup] 8.10 Implement a Hash Table 实现一个哈希表

    8.10 Design and implement a hash table which uses chaining (linked lists) to handle collisions. 这道题让 ...