POJ 2411.Mondriaan's Dream 解题报告
题意:
给出n*m (1≤n、m≤11)的方格棋盘,用1*2的长方形骨牌不重叠地覆盖这个棋盘,求覆盖满的方案数。
Solution:
位运算+状态压缩+dp
二进制数(####)代表填完一行后这一行的状态,填满的地方为1,未填的地方为0。
显然在填第i行时,能改变的仅为第i-1行和第i行,因此要满足在填第i行时,第1~i-2行已经全部填满。
DFS一行的状态,要是填完第i行时,第i-1行被填满。
因此两行的状态(p1,p2)满足,~p1=p2;
DFS出所有满足条件的状态对(P1,P2)
①第i行第k位为1,第i-1行第k位为0。(一块骨牌竖直放置)
dfs(k+1,last<<1,now<<1 | 1)
②第i行第k位为0,第i-1行第k位为1。 (第i行空出第k位)
dfs(k+1,last<<1 | 1,now<<1)
③骨牌横向放置。
bfs (k + 2, last << 2 | 3, now << 2 | 3)
转移方程:F[i][sp1]=∑f[i-1][sp2]
代码:
- #include <iostream>
- #include <cstring>
- #include <cstdio>
- #define LL long long
- using namespace std;
- int n, m, x;
- LL f[12][1 << 12];
- void dfs (int k, int last, int now) {
- if (k ==m ) f[x][now] += f[x - 1][last];
- if (k > m) return;
- dfs (k + 1, last << 1, now << 1 | 1);
- dfs (k + 1, last << 1 | 1, now << 1);
- dfs (k + 2, last << 2 | 3, now << 2 | 3);
- }
- int main() {
- while (~scanf ("%d %d", &n, &m) ) {
- if (n == 0) break;
- if (n > m) swap (n, m);
- memset (f, 0, sizeof f);
- f[0][ (1 << m) - 1] = 1;
- for (x = 1; x <= n; x++)
- dfs (0, 0, 0);
- printf ("%lld\n", f[n][ (1 << m) - 1]);
- }
- }
POJ 2411.Mondriaan's Dream 解题报告的更多相关文章
- POJ 2411 Mondriaan's Dream 插头dp
题目链接: http://poj.org/problem?id=2411 Mondriaan's Dream Time Limit: 3000MSMemory Limit: 65536K 问题描述 S ...
- 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
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Total Submissions: 18903 Accepted: 10779 D ...
- [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(状压DP)
Mondriaan's Dream Time Limit: 3000MS Memory Limit: 65536K Description Squares and rectangles fascina ...
- poj 2411 Mondriaan's Dream 轮廓线dp
题目链接: http://poj.org/problem?id=2411 题目意思: 给一个n*m的矩形区域,将1*2和2*1的小矩形填满方格,问一共有多少种填法. 解题思路: 用轮廓线可以过. 对每 ...
- poj 2411 Mondriaan's Dream(状态压缩dP)
题目:http://poj.org/problem?id=2411 Input The input contains several test cases. Each test case is mad ...
随机推荐
- Maven实战五
转载:http://www.iteye.com/topic/1123232 我们项目中用到的jar包可以通过依赖的方式引入,构建项目的时候从Maven仓库下载即可. 1. 依赖配置 依赖可以声明 ...
- java学习之函数
讲完了语句结构还有运算符.变量,下面我们来了解下函数. 那么什么是函数,函数的定义是怎样的呢? 函数的定义: 函数是指在类当中定义的一段有特殊功能的代码段,同时函数在类中也被成为方法. class F ...
- CF 85D Sum of Medians (五颗线段树)
http://codeforces.com/problemset/problem/85/D 题意: 给你N(0<N<1e5)次操作,每次操作有3种方式, 1.向集合里加一个数a(0< ...
- 数据结构(二维线段树,差分): NOI2012 魔幻棋盘
貌似想复杂了…… #include <iostream> #include <cstring> #include <cstdio> #define mid ((l+ ...
- 图论(网络流):SPOJ OPTM - Optimal Marks
OPTM - Optimal Marks You are given an undirected graph G(V, E). Each vertex has a mark which is an i ...
- openfire for mac 无法启动
http://blog.csdn.net/winer888/article/details/49886281 ①:sudo chmod -R 777 /usr/local/openfire/bin ② ...
- Python算法之---冒泡,选择,插入排序算法
''' Created on 2013-8-23 @author: codegeek ''' def bubble_sort(seq): for i in range(len(se ...
- android编程中setLayoutParams方法设置
第一篇 private LinearLayout generateHeadOfControl() { LinearLayout LayoutHead = createLayout(LinearLayo ...
- Android ViewPager FragmentPagerAdapter
ViewPager 里面放Fragment <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/and ...
- static对象的高级用法
1. 函数里static对象是local的,其他如全局对象,类里的static对象都是非local的,会在程序初始化中提前创建 2. 非local的对象的创建无法确定先后次序,但能保证在main函数前 ...