Mondriaan's Dream

题目链接

Problem 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 file 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

经典的一道轮廓线dp题

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> PII;
#define inf 0x3f3f3f3f
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll MAXN = 1e6 + 7;
const ll MAXM = 1e3 + 7;
const ll MOD = 1e9 + 7;
const double eps = 1e-6;
int n, m, cur;
ll dp[2][1 << 15]; //滚动数组
void update(int from, int to)
{
if (to & (1 << m)) //判断溢出的一位是不是1,是0则不合法
dp[cur][to ^ (1 << m)] += dp[cur ^ 1][from];
}
int main()
{
while (~scanf("%d%d", &n, &m) && n && m)
{ if ((n * m) & 1) //总格子是奇数自然不行
printf("0\n");
else
{
cur = 0;
if (m > n)
swap(n, m);
int top = 1 << m;
dp[cur][top - 1] = 1; //轮廓线上方
for (int i = 0; i < n; i++)
{
for (int j = 0; j < m; j++)
{
cur ^= 1;
memset(dp[cur], 0, sizeof(dp[cur]));
for (int k = 0; k < top; k++) /* 转移轮廓线上的状态 */
{
/* 不放 直接转移*/
update(k, k << 1);
/* 往上放 上为0,当I=0时不可往上摆*/
if (i && !(k & (1 << m - 1)))
update(k, (k << 1) ^ (1 << m) ^ 1);
/* 往左放 左为0,上为1 ,j=0时不可往左摆*/
if (j && !(k & 1))
update(k, (k << 1) ^ 3);
}
}
}
printf("%lld\n", dp[cur][(1 << m) - 1]);
}
}
return 0;
}

Mondriaan's Dream 轮廓线DP 状压的更多相关文章

  1. POJ2411 Mondriaan's Dream 轮廓线dp

    第一道轮廓线dp,因为不会轮廓线dp我们在南京区域赛的时候没有拿到银,可见知识点的欠缺是我薄弱的环节. 题目就是要你用1*2的多米诺骨排填充一个大小n*m(n,m<=11)的棋盘,问填满它有多少 ...

  2. poj 2411 Mondriaan's Dream 轮廓线dp

    题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...

  3. 【HDU】4352 XHXJ's LIS(数位dp+状压)

    题目 传送门:QWQ 分析 数位dp 状压一下现在的$ O(nlogn) $的$ LIS $的二分数组 数据小,所以更新时直接暴力不用二分了. 代码 #include <bits/stdc++. ...

  4. 【BZOJ】1076 [SCOI2008]奖励关 期望DP+状压DP

    [题意]n种宝物,k关游戏,每关游戏给出一种宝物,可捡可不捡.每种宝物有一个价值(有负数).每个宝物有前提宝物列表,必须在前面的关卡取得列表宝物才能捡起这个宝物,求期望收益.k<=100,n&l ...

  5. CCF 201312-4 有趣的数 (数位DP, 状压DP, 组合数学+暴力枚举, 推公式, 矩阵快速幂)

    问题描述 我们把一个数称为有趣的,当且仅当: 1. 它的数字只包含0, 1, 2, 3,且这四个数字都出现过至少一次. 2. 所有的0都出现在所有的1之前,而所有的2都出现在所有的3之前. 3. 最高 ...

  6. HDU5731 Solid Dominoes Tilings 状压dp+状压容斥

    题意:给定n,m的矩阵,就是求稳定的骨牌完美覆盖,也就是相邻的两行或者两列都至少有一个骨牌 分析:第一步: 如果是单单求骨牌完美覆盖,请先去学基础的插头dp(其实也是基础的状压dp)骨牌覆盖 hiho ...

  7. HDU 1400 (POJ 2411 ZOJ 1100)Mondriaan's Dream(DP + 状态压缩)

    Mondriaan's Dream Problem Description Squares and rectangles fascinated the famous Dutch painter Pie ...

  8. POJ 2404 Jogging Trails [DP 状压 一般图最小权完美匹配]

    传送门 题意:找一个经过所有边权值最小的回路,$n \le 15$ 所有点度数为偶则存在欧拉回路,直接输出权值和 否则考虑度数为奇的点,连着奇数条边,奇点之间走已经走过的路移动再走没走过的路 然后大体 ...

  9. BZOJ 2595: [Wc2008]游览计划 [DP 状压 斯坦纳树 spfa]【学习笔记】

    传送门 题意:略 论文 <SPFA算法的优化及应用> http://www.cnblogs.com/lazycal/p/bzoj-2595.html 本题的核心就是求斯坦纳树: Stein ...

随机推荐

  1. git之本地篇(用tortoisegit操作)

    下载: git:https://git-scm.com/downloads tortoisegit(小乌龟):https://tortoisegit.org/ ortoisegit中文语言包 v2.9 ...

  2. DOCKER学习_006:Docker存储驱动

    一 镜像的分层特性 在说docker的文件系统之前,我们需要先想清楚一个问题.我们知道docker的启动是依赖于image,docker在启动之前,需要先拉取image,然后启动.多个容器可以使用同一 ...

  3. $CH0601\ Genius\ ACM$ 倍增优化DP

    ACWing Description 给定一个长度为N的数列A以及一个整数T.我们要把A分成若干段,使得每一段的'校验值'都不超过N.求最少需要分成几段. Sol 首先是校验值的求法: 要使得'每对数 ...

  4. jib-maven-plugin构建镜像

    序言 在本次期末设计当中,应为需要做部署脚本,我们采用的是dockerfile+docker-compose的部署方式,这种方式对vue项目是没有问题的,因为vue下载依赖与打包是分离开来的,即使修改 ...

  5. 「2018-11-05模拟赛」T5 传送机 解题报告

    5.传送机(sent.*) 问题描述: 黄黄同学要到清华大学上学去了.黄黄同学很喜欢清华大学的校园,每次去上课时总喜欢把校园里面的每条路都走一遍,当然,黄黄同学想每条路也只走一遍. 我们一般人很可能对 ...

  6. Eclipse中安装LEAP插件

    点击eclipse中顶部菜单栏中 Help 项,选择 Install New Software... 项 在弹出安装窗口中点击 Add... 在弹出的添加安装软件的窗口中点击 Local... 选择插 ...

  7. 虚拟机安装LEDE旁路由实现软路由功能

    如何在虚拟上安装LEDE软路由,接下来我们一步一步操作. 1.首先到https://firmware.koolshare.cn/ 下载虚拟机下专用盘如图标记均可 2.虚拟机创建 选择下载好的文件 保持 ...

  8. 学会python正则表达式就是这么简单

    一前言 本篇文章带大家快速入门正则表达式的使用,正则表达式的规则不仅适用python语言,基本大多数编程语言都适用,在日常使用中极为广泛,读者们有必要学好正则表达式.看完这篇文章,读者们要理解什么是正 ...

  9. Idea 注册方式,亲测可用

    参考:https://www.cnblogs.com/aacoutlook/p/9036299.html 2018年3月 <License server>方式不能使用了,只好尝试<A ...

  10. Fabric1.4:手动启动 first-network 网络(一)

    注意:本文所使用的 fabric 版本为 v1.4.3,与其它版本的网络存在差异. 手动启动 first-network 网络系列分为三部分: 手动启动 first-network 网络(一) 手动启 ...