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

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



Sample Output



题意:


给出n * m的棋盘,问用1 * 2的骨牌铺满棋盘的方案数。

分析:


棋盘n,m很小,可以想到状压dp。一般的状压dp是枚举上一维的状态和当前这维状态然后转移。

在蓝书上P384页,也有一种解法。但是网上有另一种做法:http://blog.csdn.net/sf____/article/details/15026397

十分感谢博主的思路。

思路是这样的:

依然定义f[i][j][k],i为第i行,j为第第j列。k为二进制数,1 - k - 1位为当前行状态,k - m 为上一行状态,当前更新把第k位从上一行更新成当前行状态。

二进制中0表示下一行这个位置可以放数(即当前位置不放或者横着放),1表示下一行这个位置不可以放数(即当前位置竖着放)

可以得到dp状态:

dp[i][j][k ^ (1 << j)] += dp[i][j - 1][k]; -- 1 //竖着放 或者不放,因为不可能连续两行不放,所以k ^ (1 << j)和k相同位置必须有一位为1

dp[i][j][k ^ (1 << (j - 1))] += dp[i][j - 1][k]; --2 //从前一格竖着放的转移到当前位置横着放的 条件:当前这位上一格必须放了

因为i 和 j其实是刷表的,可以转移成dp[2][k];就可以了

AC代码:


# include <iostream>
# include <cstdio>
# include <cstring>
using namespace std;
const int N = << ;
long long dp[][N];
int n,m,data;
int main(){
while(~scanf("%d %d",&m,&n) && (n + m)){
data = ( << m);
if(m > n)swap(n,m);
int now = ;
memset(dp[now],,sizeof dp[now]);
dp[now][] = ;
for(int i = ;i < n;i++){
for(int j = ;j < m;j++){
now ^= ;
memset(dp[now],,sizeof dp[now]);
for(int k = ;k < data;k++)if(dp[now ^ ][k]){
dp[now][k ^ ( << j)] += dp[now ^ ][k];
if(j && (k & ( << (j - ))) && !(k & ( << j)))
dp[now][k ^ ( << (j - ))] += dp[now ^ ][k];
}
}
}
printf("%lld\n",dp[now][]);
}
}

[Poj2411]Mondriaan's Dream(状压dp)(插头dp)的更多相关文章

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

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

  2. $POJ2411\ Mondriaan's\ Dream$ 状压+轮廓线$dp$

    传送门 Sol 首先状压大概是很容易想到的 一般的做法大概就是枚举每种状态然后判断转移 但是这里其实可以轮廓线dp 也就是从上到下,从左到右地放方块 假设我们现在已经放到了$(i,j)$这个位置 那么 ...

  3. POJ 2411 Mondriaan's Dream ——状压DP 插头DP

    [题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...

  4. POJ 2411 Mondriaan's Dream -- 状压DP

    题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...

  5. Poj 2411 Mondriaan's Dream(状压DP)

    Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...

  6. POJ-2411 Mondriann's Dream (状压DP)

    求把\(N*M(1\le N,M \le 11)\) 的棋盘分割成若干个\(1\times 2\) 的长方形,有多少种方案.例如当 \(N=2,M=4\)时,共有5种方案.当\(N=2,M=3\)时, ...

  7. P1879 [USACO06NOV]玉米田Corn Fields 状压dp/插头dp

    正解:状压dp/插头dp 解题报告: 链接! ……我真的太菜了……我以为一个小时前要搞完的题目调错误调了一个小时……90分到100我差不多搞了一个小时…… 然后这题还是做过的……就很气,觉得确实是要搞 ...

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

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

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

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

随机推荐

  1. IE8 window.open 不支持此接口 的问题解决

    在使用vs2010调试代码时,突然出现 window.open 不支持此接口的提示,开始认为是不是vs的问题,后来上网查询说是系统问题.我不想重装系统,之后发现是IE的问题,使用其他浏览器浏览系统不会 ...

  2. 第一周作业javaee strainmap

  3. MVVM没你想象的那么的好

    我写过很多有关于让View Controller 更易于理解的文章,其中一种比较常见的模式就是Model-View-ViewModel(MVVM). 我认为MVVM 是一种非常容易让人混淆的 anti ...

  4. System类与两种输入流

    1.System类对I/O的支持系统输出System.out.println 是利用了I/O流的模式完成的.实际是打印流PrintStream对象 System类中定义了三个操作的常量 1.标准/系统 ...

  5. Python 中列表、元祖、字典

    1.元祖: 对象有序排列,通过索引读取读取, 对象不可变,可以是数字.字符串.列表.字典.其他元祖 2.列表: 对象有序排列,通过索引读取读取, 对象是可变的,可以是数字.字符串.元祖.其他列表.字典 ...

  6. FormItem label 属性 可以改成 slot模式 就能加入br回车了 iview

    FormItem label 属性 可以改成 slot模式 就能加入br回车了 iview <FormItem> <div slot='label'>测试文字<br> ...

  7. 基础数据类型(set集合)

    认识集合 由一个或多个确定的元素所构成的整体叫做集合. 集合中的元素有三个特征: 1.确定性(集合中的元素必须是确定的) 2.互异性(集合中的元素互不相同.例如:集合A={1,a},则a不能等于1) ...

  8. 课外作业(建立double类型的小数,按照四舍五入保留2位小数)

    举例:

  9. vue之组件的使用(转载)

    在工程目录/src下的component文件夹下创建一个 firstcomponent.vue并写仿照 App.vue 的格式和前面学到的知识写一个组件. <template> <d ...

  10. 剑指Offer整理笔记

    说在前面,本篇的目的是为了学习剑指offer,以及博客园的排版功能,并将文章排版得整洁得体. 梵蒂冈梵蒂冈地方官方