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. Java中的循环结构

    1.while循环结构 语法: while(循环条件){ //循环操作 } while循环结构流程图: 举例: int i = 1; while(i <= 100){ System.out.pr ...

  2. Python3使用Pyintaller-打包成exe

    Pyinstaller打包exe执行文件 安装Pyinstaller 使用pip安装Pyinstaller 用管理员模式运行cmd,输入命令: pip install pyinstaller 此方法会 ...

  3. 修改kubelet启动参数

    我是用kubeadm安装的k8s,现在通过Aqua扫描出相关配置问题,需要修改kubelet的启动参数: 默认配置文件名为:10-kubeadm.conf #vim /usr/lib/systemd/ ...

  4. 【题解】P4503 [CTSC2014]企鹅QQ(哈希)

    [题解]P4503 [CTSC2014]企鹅QQ(哈希) 考虑这样一种做法,将每个字符串的删去某个字符的新字符串的哈希值存下来,然后最后\(sort\)一遍双指针统计每个值相同的数的个数\(x\),这 ...

  5. 【题解】BZOJ1034 [ZJOI2008]泡泡堂BNB(贪心)

    [题解]BZOJ1034 [ZJOI2008]泡泡堂BNB(贪心) 考虑直接模拟田忌赛马... 我的最小比你的大,直接上 我的最大比你的大,直接上 otherwise,我小换你大 考虑最劣,由于每次比 ...

  6. Linux系统之运行状态分析及问题排查思路

    〇.一件事儿 以下分析是站在Java工程师的角度来分析的. 一.CPU分析 分析CPU的繁忙程度,两个指标:系统负载和CPU利用率 1.系统负载分析 系统负载:在Linux系统中表示,一段时间内正在执 ...

  7. my_mysql

    ###一键偷懒YUM安装MySQbL### 1.安装mysql数据库 #yum install -y mariadb-server  mariadb 2.登录mysql数据库常用选项 -h:指定服务端 ...

  8. Don’t Repeat Yourself,Repeat Yourself

    Don't Repeat Yourself,Repeat Yourself Don't repeat yourself (DRY, or sometimes do not repeat yoursel ...

  9. Centos 中文乱码解决方法

    问题描述 crontab -e 添加定时任务时,直接将下面内容粘贴过去,结果竟然乱码了. # 每个星期日凌晨3:00执行完全备份脚本 0 3 * * 0 /bin/bash -x /root/bash ...

  10. spring同时操作多数据库 多个mysql和mongoDB,不需切换数据源,同时操作mysql和mongodb

    源码:https://github.com/haihai1172/spring-mysql-mongoDB 项目目录 1.环境搭建,java-sdk 1.8 具体怎么搭建,就不说了 2.配置jdbc. ...