POJ 2411 Mondriaan's Dream 插头dp
题目链接:
http://poj.org/problem?id=2411
Mondriaan's Dream
Time Limit: 3000MSMemory Limit: 65536K
#### 问题描述
> 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!
#### 输入
> 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 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.
####样例输入
> 1 2
> 1 3
> 1 4
> 2 2
> 2 3
> 2 4
> 2 11
> 4 11
> 0 0
>
####样例输出
> 1
> 0
> 1
> 2
> 3
> 5
> 144
> 51205
题意
用
1*2和2*1的骨牌排满n*m的方格。
题解
插头dp入门题
参考:port
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef long long LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=13;
LL dp[2][1<<maxn];
int n,m;
int main() {
while(scf("%d%d",&n,&m)==2&&n){
if(n<m) swap(n,m);
int pre=0,cur=1;
clr(dp[cur],0);
dp[cur][0]=1;
for(int i=0;i<n;i++){
for(int j=0;j<m;j++){
swap(pre,cur);
clr(dp[cur],0);
int p1=(1<<j),p2=(1<<(j+1));
for(int k0=0;k0<(1<<(m+1));k0++){
int k=k0;
///注意!换行的时候的处理
if(!j) k=k0<<1;
if((p1&k)&&!(p2&k)){
dp[cur][k^p1]+=dp[pre][k0];
}else if(!(p1&k)&&(p2&k)){
dp[cur][k^p2]+=dp[pre][k0];
}else if(!(p1&k)&&!(p2&k)){
if(j<m-1) dp[cur][k^p2]+=dp[pre][k0];
if(i<n-1) dp[cur][k^p1]+=dp[pre][k0];
}
}
}
}
prf("%lld\n",dp[cur][0]);
}
return 0;
}
//end-----------------------------------------------------------------------
POJ 2411 Mondriaan's Dream 插头dp的更多相关文章
- poj 2411 Mondriaan's Dream 轮廓线dp
题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...
- POJ 2411 Mondriaan's Dream ——状压DP 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- POJ 2411 Mondriaan's Dream -- 状压DP
题目:Mondriaan's Dream 链接:http://poj.org/problem?id=2411 题意:用 1*2 的瓷砖去填 n*m 的地板,问有多少种填法. 思路: 很久很久以前便做过 ...
- Poj 2411 Mondriaan's Dream(压缩矩阵DP)
一.Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One night, ...
- POJ - 2411 Mondriaan's Dream(轮廓线dp)
Mondriaan's Dream Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nig ...
- Poj 2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- [poj 2411]Mondriaan's Dream (状压dp)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- [POJ] 2411 Mondriaan's Dream
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
随机推荐
- 20145202马超 2016-2017-2 《Java程序设计》第9周学习总结
20145202马超 2016-2017-2 <Java程序设计>第9周学习总结 教材学习内容总结 JDBC 数据库本身是个独立运行的应用程序 撰写应用程序是利用通信协议对数据库进行指令交 ...
- Linux部署python django程序-apache
1.安装Apache 先卸载自带的httpd rpm -e httpd --nodeps 在网上下载四个文件 1.apr-1.4.6.tar.gz 2.apr-util-1.5.1.tar.gz 3. ...
- C++实现tar包解析
tar(tape archive)是Unix和类Unix系统上文件打包工具,可以将多个文件合并为一个文件,使用tar工具打出来的包称为tar包.一般打包后的文件名后缀为".tar" ...
- 9 ORM-高阶补充(未完成)
https://www.cnblogs.com/alice-bj/p/9195846.html#_labelTop https://www.cnblogs.com/yuanchenqi/article ...
- burpsuite 抓取https 证书问题
一定要按照步骤来,先导入burp初始证书到服务器,这时候初始证书是未验证的,然后导出为crt/cer文件(可能拼写错误,总之是正规证书后缀),再导入到机构. 要代理所有类型包括ssl的才能正常导入机构 ...
- Zabbix实战-简易教程--日志类
一.主动模式和被动模式介绍 要监控日志,必须使用主动模式,那么,什么是主动模式?什么是被动模式呢? 1.主动模式和被动模式 主动模式 主动模式通讯过程: ● Agent打开TCP连接(主动检测变成Ag ...
- UWP Xaml设计器中输入特殊字符
<TextBox Text="欢迎使用小冰科技最新研发的自然语言处理程序.小冰科技旗下还有强大的人脸识别软件——<微识别>,自动追踪和识别人脸:具有科普性质的.清新脱俗的识 ...
- node.js学习笔记(二)——回调函数
Node.js 异步编程的直接体现就是回调. 那什么是回调呢?回调指的是将一个函数作为参数传递给另一个函数,并且通常在第一个函数完成后被调用.需要指明的是,回调函数不是由该函数的实现方直接调用,而是在 ...
- 开源第三方登录组件OAuthLogin2.0 架构解析及开源地址
OAuthLogin2.0介绍地址: 入门地址:http://www.cnblogs.com/dazhuangtage/p/6306133.html Nuget地址:https://www.nuget ...
- Qt-网易云音乐界面实现-4 实现推荐列表和我的音乐列表,重要在QListWidget美化
来标记下这次我么实现的部分 这次我们来是试下这部分功能,来对比一下,左边是原生,右面是我写的,按着模仿的海可以哈,就有有的资源不是一样了,因为我连抠图都懒得扣了了 好了,现在就是我的是先过程了,主要教 ...