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. Python的类和函数的魔法

    class CustomClass: def customFun(self, id): print("fun_1",id ) if __name__ == '__main__': ...

  2. 蔡勒(Zeller)公式

    来源好搜百科:http://baike.haosou.com/doc/1048888-1109421.html 蔡勒(Zeller)公式,是一个计算星期的公式,随便给一个日期,就能用这个公式推算出是星 ...

  3. (转)mysql执行计划分析

    转自:https://www.cnblogs.com/liu-ke/p/4432774.html MySQL执行计划解读   Explain语法 EXPLAIN SELECT …… 变体: 1. EX ...

  4. MathType如何编辑手写体l

    MathType在编辑公式不仅方便而且规范,并且能够根据自己的需要选择不同的字体进行使用,可以是正体也可以是斜体,可以是新罗马体,也可以是花体,这些用word公式编辑器MathType都是可以的.还有 ...

  5. Swift学习笔记之--类和对象

    通过在 class后接类名称来创建一个类.在类里边声明属性与声明常量或者变量的方法是相同的,唯一的区别的它们在类环境下.同样的,方法和函数的声明也是相同的写法 class Shape { func s ...

  6. android中必备的接口回调用法

    1 ,这个方法很常见,本人觉得也很实用,分享下吧 public class DirverDistanceTool { public void getDirverDistance(LatLng star ...

  7. 打开Linux ftp服务,如:vsftpd: unrecognized service

    打开Linux ftp服务,如:vsftpd: unrecognized service   [root@BZXXDBS02 ~]# service vsftpd start vsftpd: unre ...

  8. centos solr4.5 tomcat 简单安装[已测试ok]

    一.环境准备: 1.jdk安装 2.tomcat安装 这两个基本环境的安装在这里就不说了 二.下载solr-4.5.0.tgz 三.安装solr 1.解压solr tar -zxvf /opt/sol ...

  9. Parquet存储格式 - 论文翻译【转】

    Apache Parquet是Hadoop生态圈中一种新型列式存储格式,它可以兼容Hadoop生态圈中大多数计算框架(Mapreduce.Spark等),被多种查询引擎支持(Hive.Impala.D ...

  10. [置顶] Linux协议栈代码阅读笔记(二)网络接口的配置

    Linux协议栈代码阅读笔记(二)网络接口的配置 (基于linux-2.6.11) (一)用户态通过C库函数ioctl进行网络接口的配置 例如,知名的ifconfig程序,就是通过C库函数sys_io ...