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. apropos命令

    apropos——查看配置文件功能 示例1: # apropos ifconfig 显示ifconfig配置文件的功能,类似于执行man命令时的NAME信息

  2. type和isinstance区别

    type只能对类型做直接的判断,主要用于获取未知变量的类型. 在程序中几乎很少用到type. 而isinstance功能比type更强,可以对子类型做出推理判断. isinstance主要用于判断A是 ...

  3. CAD交互绘制带周长面积的矩形框(网页版)

    主要用到函数说明: _DMxDrawX::DrawLine 绘制一个直线.详细说明如下: 参数 说明 DOUBLE dX1 直线的开始点x坐标 DOUBLE dY1 直线的开始点y坐标 DOUBLE ...

  4. python读取绝对路径的三种方式

    import pandas as pd dood_inf0=pd.read_csv("C:\\Users\\Administrator\\Desktop\\food_info.csv&quo ...

  5. Maven实战读书笔记(二):Maven坐标与仓库

    2.1 Maven坐标 Maven坐标是Maven用来表示一个组件依赖的标示. Maven通过下面几个元素定义坐标:groupId.artifactId.version.packaging.class ...

  6. 01Ping程序的设计

    1.Ping程序设计具体设计任务 1.1 实验目的 PING程序是我们使用的比较多的用于测试网络连通性的程序.PING程序基于ICMP,使用ICMP的回送请求和回送应答来工作.由计算机网络课程知道,I ...

  7. [CF] 950B Intercepted Message

    B. Intercepted Message time limit per test1 second memory limit per test512 megabytes inputstandard ...

  8. ubuntu14.04 RockMongo的配置

    安装php5 安装php5     sudo apt-get install php5 让Apache支持php      sudo apt-get install libapache2-mod-ph ...

  9. Python的串口

    要使用python中的串口,可以下载pywin32-224-cp36-cp36m-win_amd64.whl去安装或者pip install去安装. 调试下来,有一点很不爽,读取read()数据的ti ...

  10. 根据不同的产品id获得不同的下拉选项 (option传多值)

    <td> 没有 value 所以要在<td>里面加上input  同时text 为hidden这样就不会显示value的值 <td><select id='g ...