链接:http://poj.org/problem?id=2411

题意:题目描写叙述:用1*2 的矩形通过组合拼成大矩形。求拼成指定的大矩形有几种拼法。

參考博客:http://blog.csdn.net/shiwei408/article/details/8821853

思路:我看了上面的博客,想了非常久才明确是怎样处理状态的。

因为是1 * 2,所以能够通过相邻两行的转化关系来推导。

两行铺不铺砖能够用二进制来表示,可是假设暴力枚举,大概有2^10 * 2 ^ 10 次那么多状态(尽管当中有非常多状态是没实用的)。

所以採用dfs来枚举各种可行状态:

状态标记 横放和竖放的下一个均为1。竖放的上一个和不放置为0 ,每行能够转化为1个2进制数。当这一行訪问结束时,就会得到上一行状态。和该行状态,由于全部情况都是我们设置的,所以pre状态一定会转化为now状态

对于每个位置,我们有三种放置方法:1. 竖直放置2. 水平放置3. 不放置

d为当前列号 ,初始化d, now, pre都为0。now为当前行。pre为当前行的上一行

1. d = d + 1, now << 1 | 1, pre << 1;   // 竖直放置。当前行该列为1,上一行该列置为0

2. d = d + 2, now << 2 | 3, pre<< 2 | 3;  // 横放 都为11(由于当两行的状态往下推时,必需要保证pre这一行摆满。所以pre也都为11)

3. d = d + 1, now << 1, pre<< 1 | 1;    // 上一行该列置为1,不能竖放。不放置的状态

由于转移状态有非常多种,所以用dfs去枚举各种可行的状态。

最后在转移的时候,dp[0][(1 << w) - 1] = 1 表示仅仅有第0行所有铺满才行。

仅仅须要算到 h - 1 行,然后 h 行所有铺满为答案。

代码:

/*
ID: wuqi9395@126.com
PROG:
LANG: C++
*/
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdio>
#include<vector>
#include<string>
#include<fstream>
#include<cstring>
#include<ctype.h>
#include<iostream>
#include<algorithm>
#define INF (1<<30)
#define PI acos(-1.0)
#define mem(a, b) memset(a, b, sizeof(a))
#define rep(i, n) for (int i = 0; i < n; i++)
#define debug puts("===============")
#define eps (1e-6)
typedef long long ll;
using namespace std;
const int maxn = 13;
int w, h, cnt;
ll dp[13][2100];
int sta[14000][2];
void dfs(int l, int now, int pre) {
if (l > w) return ;
if (l == w) {
sta[cnt][0] = pre, sta[cnt++][1] = now;
return ;
}
dfs(l + 2, (now << 2) | 3, (pre << 2) | 3);
dfs(l + 1, (now << 1) | 1, pre << 1);
dfs(l + 1, now << 1, (pre << 1) | 1);
}
int main () {
while(~scanf("%d%d", &h, &w), h || w) {
if (h < w) swap(h, w);
cnt = 0;
dfs(0, 0, 0);
memset(dp, 0, sizeof(dp));
dp[0][(1 << w) - 1] = 1;
rep(i, h) {
rep(j, cnt) {
dp[i + 1][sta[j][1]] += dp[i][sta[j][0]];
}
}
printf("%lld\n", dp[h][(1 << w) - 1]);
}
return 0;
}

版权声明:本文博客原创文章,博客,未经同意,不得转载。

POJ 2411 Mondriaan&#39;s Dream (dp + 减少国家)的更多相关文章

  1. poj 2411 Mondriaan&#39;s Dream 【dp】

    题目:id=2411" target="_blank">poj 2411 Mondriaan's Dream 题意:给出一个n*m的矩阵,让你用1*2的矩阵铺满,然 ...

  2. POJ 2411 Mondriaan&#39;s Dream

    状压DP Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 9938 Accepted: 575 ...

  3. 状压DP POJ 2411 Mondriaan'sDream

    题目传送门 /* 题意:一个h*w的矩阵(1<=h,w<=11),只能放1*2的模块,问完全覆盖的不同放发有多少种? 状态压缩DP第一道:dp[i][j] 代表第i行的j状态下的种数(状态 ...

  4. POJ 2411 Mondriaan's Dream 插头dp

    题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...

  5. Poj 2411 Mondriaan's Dream(压缩矩阵DP)

    一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...

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

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

  7. poj 2411 Mondriaan's Dream(状态压缩dP)

    题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...

  8. poj 2411 Mondriaan's Dream(状态压缩dp)

    Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, af ...

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

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

随机推荐

  1. effective c++ 条款10 handle assignment to self operator =

    非强制性,但是个好习惯 当使用连锁赋值时很有用 x=y=z=10; class Window { public: Window& operator=(int size) { ... retur ...

  2. Tian Ji -- The Horse Racin

    Tian Ji -- The Horse Racin Problem Description Here is a famous story in Chinese history. "That ...

  3. Hive自己定义函数的使用——useragent解析

    想要从日志数据中分析一下操作系统.浏览器.版本号使用情况.可是hive中的函数不能直接解析useragent,于是能够写一个UDF来解析.useragent用于表示用户的当前操作系统,浏览器版本号信息 ...

  4. Android 随着输入框控件的清除功能ClearEditText,抄IOS输入框

    今天给大家带来一个非常有用的小控件ClearEditText,就是在Android系统的输入框右边增加一个小图标,点击小图标能够清除输入框里面的内容,IOS上面直接设置某个属性就能够实现这一功能.可是 ...

  5. SignalR与ActiveMQ

    SignalR与ActiveMQ结合构建实时通信   一.概述 本教程主要阐释了如何利用SignalR与消息队列的结合,实现不同客户端的交互 SignalR如何和消息队列交互(暂使用ActiveMQ消 ...

  6. POJ3623:Best Cow Line, Gold(后缀数组)

    Description FJ is about to take his N (1 ≤ N ≤ 30,000) cows to the annual"Farmer of the Year&qu ...

  7. OCP-1Z0-051-题目解析-第14题

    14. Using the CUSTOMERS table,  you need to generate a report that shows 50% of each credit        a ...

  8. HDU 4391 Paint The Wall 段树(水

    意甲冠军: 特定n多头排列.m操作 以下是各点的颜色 以下m一种操纵: 1 l r col 染色 2 l r col 问间隔col色点 == 通的操作+区间内最大最小颜色数的优化,感觉非常不科学... ...

  9. [模拟Android微信]主界面

    首先看很像模仿: 走出来: 实现过程: 依赖类库:actionbarsherlock 用actionbarsherlock来实现顶部的搜索的效果. tab用的是Viewpaper实现的. 详细细节: ...

  10. 【Git使用具体解释】EGit使用具体解释

    此系列文章写给那些打算使用Git或正在使用Git,但对Git还不是非常理解的程序员们,希望能帮助大家在学习和使用Git的过程中少走弯路,并以最少的时间和代价来熟悉Git,让Git可以辅助很多其它的开发 ...