POJ 题目2411 Mondriaan's Dream(状压DP)
Time Limit: 3000MS | Memory Limit: 65536K | |
Total Submissions: 13519 | Accepted: 7876 |
Description

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

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
196K | 16MS |
#include<stdio.h>
#include<string.h>
#define LL __int64
LL dp[2][1<<12];
int n,m;
LL add;
void dfs(int i,int p,int pos)
{
if(pos==m)
{
dp[i][p]+=add;
return;
}
dfs(i,p,pos+1);
if(pos<m-1&&!(p&(1<<pos))&&!(p&(1<<(pos+1))))
{
dfs(i,p|(1<<pos)|(1<<(pos+1)),pos+2);
}
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF,n||m)
{
if(n*m%2)
{
printf("0\n");
continue;
}
int rt=(1<<m)-1;
memset(dp,0,sizeof(dp));
add=1;
dfs(0,0,0);
int i,j;
for(i=1;i<n;i++)
{
memset(dp[i%2],0,sizeof(dp[i%2]));
for(j=0;j<=rt;j++)
{
if(dp[(i-1)%2][j])
{
add=dp[(i-1)%2][j];
dfs(i%2,~j&rt,0);
}
}
}
printf("%I64d\n",dp[(n-1)%2][rt]);
}
}
POJ 题目2411 Mondriaan's Dream(状压DP)的更多相关文章
- 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 插头DP
[题目分析] 用1*2的牌铺满n*m的格子. 刚开始用到动规想写一个n*m*2^m,写了半天才知道会有重复的情况. So Sad. 然后想到数据范围这么小,爆搜好了.于是把每一种状态对应的转移都搜了出 ...
- Poj 2411 Mondriaan's Dream(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- [poj2411] Mondriaan's Dream (状压DP)
状压DP Description Squares and rectangles fascinated the famous Dutch painter Piet Mondriaan. One nigh ...
- POJ 2411 Mondriaan'sDream(状压DP)
题目大意:一个矩阵,只能放1*2的木块,问将这个矩阵完全覆盖的不同放法有多少种. 解析:如果是横着的就定义11,如果竖着的定义为竖着的01,这样按行dp只需要考虑两件事儿,当前行&上一行,是不 ...
- POJ 3311 Hie with the Pie (状压DP)
dp[i][j][k] i代表此层用的状态序号 j上一层用的状态序号 k是层数&1(滚动数组) 标准流程 先预处理出所有合法数据存在status里 然后独立处理第一层 然后根据前一层的max推 ...
- POJ 1321 棋盘问题(DFS & 状压DP)
用DFS写当然很简单了,8!的复杂度,16MS搞定. 在Discuss里看到有同学用状态压缩DP来写,就学习了一下,果然很精妙呀. 状态转移分两种,当前行不加棋子,和加棋子.dp[i][j]中,i代表 ...
- POJ:1185-炮兵阵地(状压dp入门)
炮兵阵地 Time Limit: 2000MS Memory Limit: 65536K Description 司令部的将军们打算在N*M的网格地图上部署他们的炮兵部队.一个N*M的地图由N行M列组 ...
- poj 2404 中国邮递员问题 欧拉回路判定+状压dp
/* 状压dp 邮递员问题:求经过任意点出发经过每一条边一次并回到原点. 解法:1.如果是欧拉回路那么就是所有的边的总和. 2.一般的解法,找出所有的奇度顶点,任意两个顶点匹配,即最小完美匹配,可用状 ...
随机推荐
- Java学习路线图,专为新手定制的Java学习计划建议
怎么学习Java,这是很多新手经常会问我的问题,现在我简单描述下一个Java初学者到就业要学到的一些东西: 首先要明白Java体系设计到得三个方面:J2SE,J2EE,J2ME(KJAVA).J ...
- 16个基本颜色关键字 Basic color keywords
16个基本颜色关键字 Basic color keywords Color Color Name HEX RGB black #000000 0,0,0 silver #C0C0C0 192, ...
- 转:如何实现一个malloc
如何实现一个malloc 转载后排版效果很差,看原文! 任何一个用过或学过C的人对malloc都不会陌生.大家都知道malloc可以分配一段连续的内存空间,并且在不再使用时可以通过free释放掉. ...
- HTML5 十大新特性(八)——Web Worker
由于js是单线程的,所以H5添加了这个叫做webWorker的概念,允许js创建多个线程,但是子线程完全受主线程控制,且不能操作DOM,从而来处理一些比较耗时的操作. 那么如何创建一个子线程呢?通过这 ...
- Oracle分页查询=======之伪列的使用
========伪列========== 在Oracle数据库中,伪列不存在表中,但是可以从表中查询到 例如:SELECT ROWID 伪列,tname 教师姓名 FROM teacher; ==== ...
- [WPF]TextTrimming截断后,ToolTip显示完整信息
文本过长被截断后,用ToolTip显示完整信息. 文本未被截断,则不显示ToolTip. 值转换器: public class TrimmedTextBlockVisibilityConverter ...
- Matrix
记载: Matrix Matrix是Android 提供的一个矩阵工具类,位于"android.graphics.Matrix"包下,它本身不能对图像或View进行变换, 但它可以 ...
- 组件嵌套+Mixin函数demo
非DOM属性:1.dangerouslysetInnerHTML(xxs跨站攻击) 2.key 3.ref 编写组件嵌套 <!DOCTYPE html><html> < ...
- 使用requestAnimationFrame做动画效果一
最近学习了requestAnimationFrame,看了张鑫旭直白易懂,但是某些地方语言过于裸露的文章http://www.zhangxinxu.com/wordpress/2013/09/css3 ...
- UDP的connect函数
UDP的connect没有三次握手过程,内核只是检测是否存在立即可知的错误(如一个显然不可达的目的地), 记录对端的的IP地址和端口号,然后立即返回调用进程. 未连接UDP套接字(unconnecte ...