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

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

题意:

给定一个h*w的矩形。将矩形划分成1*2的小格子,有多少种方案。

思路:

考虑用行数作为状态,但是转移下一行时需要上一行的划分状态。

所以我们多开一维用于记录状态。用一个整数表示。第k位是1表示第i行第k列的格子是一个竖着的1*2长方形的上半部分。

那么对于第i+1行的状态j, j&k=0表示没有两个相邻行的相同列的格子都是长方形的上半部分。

j|k的二进制表示中,每一段连续的0都是偶数个。j|k是0的位,要么是j和k该位都是0说明这是一个横着的矩形。

只有这两种情况都满足时,(i, k)才能转移到(i+1, j)。

最后一行要输出的应该是没有一个1的情况。

注意要使用long long

 //#include <bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<stdio.h>
#include<cstring>
#include<vector>
#include<map>
#include<set> #define inf 0x3f3f3f3f
using namespace std;
typedef long long LL; int h, w;
const int maxn = << ;
bool in_s[maxn];
long long dp[][maxn]; int main(){
while(scanf("%d%d", &h, &w) != EOF && (h || w)){
for(int i = ; i < << w; i++){
bool cnt = , has_odd = ;
for(int j = ; j < w; j++){
if(i >> j & ) has_odd |= cnt, cnt = ;
else cnt ^= ;
}
in_s[i] = has_odd | cnt ? : ;
} //memset(dp, 0, sizeof(dp));
dp[][] = ;
for(int i = ; i <= h; i++){
for(int j = ; j < << w; j++){
dp[i][j] = ;
for(int k = ; k < << w; k++){
if((k & j) == && in_s[k | j]){
dp[i][j] += dp[i - ][k];
}
}
}
}
printf("%lld\n", dp[h][]);
}
return ;
}

poj2411 Mondriaan's Dream【状压DP】的更多相关文章

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

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

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

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

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

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

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

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

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

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

  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. poj2411 Mondriaan's Dream (轮廓线dp、状压dp)

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

  8. POJ 2411 Mondriaan'sDream(状压DP)

    题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...

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

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

  10. POJ2411 Mondriaan's Dream 题解 轮廓线DP

    题目链接:http://poj.org/problem?id=2411 题目大意 给你一个 \(n \times m (1 \le n,m \le 11)\) 的矩阵,你需要用若干 \(1 \time ...

随机推荐

  1. 【Java面试题】18 java中数组有没有length()方法?string没有lenght()方法?下面这条语句一共创建了多少个对象:String s="a"+"b"+"c"+"d";

    数组没有length()这个方法,有length的属性.String有有length()这个方法. int a[]; a.length;//返回a的长度 String s; s.length();// ...

  2. 对phpexcel的若干补充

    导出excel属性设置 //Include class require_once('Classes/PHPExcel.php'); require_once('Classes/PHPExcel/Wri ...

  3. nginx配置语法

    http://baijiahao.baidu.com/s?id=1604485941272024493&wfr=spider&for=pc http://blog.csdn.net/h ...

  4. mybatise 动态sql

    1. <if><choose> 动态sql 相当 <if> Java if  满足多个条件  <choose> <when>    java ...

  5. TCP/IP协议族-----24、网络管理(SNMP)

  6. mybatis由浅入深day02_2一对一查询_2.3方法二:resultMap_resultType和resultMap实现一对一查询小结

    2.3 方法二:resultMap 使用resultMap,定义专门的resultMap用于映射一对一查询结果. 2.3.1 sql语句 同resultType实现的sql SELECT orders ...

  7. POJ 2229 Sumsets(技巧题, 背包变形)

    discuss 看到有人讲完全背包可以过, 假如我自己做的话, 也只能想到完全背包了 思路: 1. 当 n 为奇数时, f[n] = f[n-1], 因为只需在所有的序列前添加一个 1 即可, 所有的 ...

  8. Android 能够暂停的录音功能

    Android ApI提供了MediaRecorder和AudioRecord两个类给开发者来很方便地实现音视频的录制(前者可以实现音频和视频的录制,后者只能实 现音频的录制).这两个类都提供了sta ...

  9. EHcache经典配置

    记录重要的东西和常用的东西. <ehcache> <!-- 指定一个文件目录,当EHCache把数据写到硬盘上时,将把数据写到这个文件目录下 --> <diskStore ...

  10. [转载]Linux I/O 调度方法

    http://scoke.blog.51cto.com/769125/490546 IO调度器的总体目标是希望让磁头能够总是往一个方向移动,移动到底了再往反方向走,这恰恰就是现实生活中的电梯模型,所以 ...