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. CentOS查看本机公网IP命令

    icanhazip.com 使你在任何地方知道你的公网IP地址 icanhazip.com是一个网址,你在浏览器中输入这个网址,你就能得到你的公网IP地址了. 我在Linux下一般使用curl ica ...

  2. C# 延时小函数 很好用

    平时我们在做winform开发的时候,有时候需要让程序休眠几秒钟,但是,如果我们直接使用 thread.sleep()函数,页面ui就会停止响应.怎么样解决呢,你可以把页面涉及到表现ui的代码放到一个 ...

  3. linux常用命令中篇

    1.打印当月的日期

  4. JavaStuNote 5

    接口 (interface) 一个抽象类,全部的方法都是抽象的,全部方法的public, 我们把这种类叫做极度抽象类,是最干瘪的类. public abstract class A { public  ...

  5. c++ c++ 与 Java

    1.c++ c++ 如果1个类的定义中包含另一个类,那么在stdafx.h中 被包含的类必须放在包含类的前面,不然编译器找不到被包含类,c++没有包的概念,所以包含头文件时要注意顺序,而java不存在 ...

  6. mysql中,查看当前数据库下所有的基表,不包括视图

    环境描述: mysql版本:5.5.57-log 操作系统版本:Red Hat Enterprise Linux Server release 6.6 (Santiago) 需求描述: 查看当前使用的 ...

  7. swift--控件工厂类的实现

    控件工厂类,简而言之就是,减少代码的复用率,只在哪里用,然后在哪里调: 代码如下: import UIKit class ViewFactory: UIView,UITextFieldDelegate ...

  8. laravel 社会化(联合)登录扩展包(QQ、微信、微博等)

    laravel的官方包只支付国外网站的联合登录:http://laravelacademy.org/post/6288.html 国内用户的话,可以用这个:https://github.com/ove ...

  9. 破解X-Pack和更新许可证

    某一天打开 Kibana 对应的 Monitoring 选项卡的时候,发现提示需要下载新的 license,旧的 license 已经过期了: 退出重新登录 发现禁止登录,提示:Login is di ...

  10. iOS - UIScrollView xib添加约束的坑

    一.Storyboard中的UIScrollView使用自动布局 在使用storyboard和xib时,我们经常要用到ScrollView,还有自动布局AutoLayout,但是ScrollView和 ...