其实这题还能用状压DP解决,可是时间达到2000ms只能过掉POJ2411.状压DP解法详见状压DP解POJ2411

贴上POJ2411AC代码 : 2000ms 时间复杂度h*w*(2^w)*(2^w)

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 1 << 11;
LL dp[12][maxn];
int w, h;
bool TestFirstLine(int state) {
	for(int i = 0; i < w;) {
		int x = 1 << i;
		if((x & state) && i+1 < w && ((x << 1) & state)) {
			i += 2;
		}
		else if(!(x & state)) ++i;
		else return false;
	}
	return true;
}

bool is_ok(int state1, int state2) {
	for(int i = 0; i < w;) {
		int x = 1 << i;
		if(!(x & state1)) {
			if(!(x & state2)) return false;
			++i;
		}
		else {
			int y = x << 1;
			if(!(x & state2)) ++i;
			else if(x & state2) {
				if(i == w-1 || !(y & state1) || !(y & state2)) return false;
				i += 2;
			}
		}
	}
	return true;
}

LL solve() {
	if(h < w) swap(w, h);
	int r = 1 << w;
	memset(dp, 0, sizeof(dp));
	//边界
	for(int i = 0; i < r; ++i)
		if(TestFirstLine(i)) dp[0][i] = 1;
	for(int i = 1; i < h; ++i)
		for(int j = 0; j < r; ++j)
			for(int k = 0; k < r; ++k) {
				if(is_ok(j, k)) dp[i][j] += dp[i-1][k];
			}
	return dp[h-1][r-1];
}

int main() {
	while(scanf("%d%d", &w, &h) == 2 && w && h) {
		printf("%lld\n", solve());
	}
	return 0;
}

对于uva11270这种状压dp会超时,使用轮廓线DP可将复杂度降低到w*h*(2^w),详细解法见训练指南P384

AC代码

#include <cstdio>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <utility>
#include <string>
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <queue>
#include <stack>
using namespace std;
#pragma comment(linker, "/STACK:1024000000,1024000000")
#define eps 1e-10
#define inf 0x3f3f3f3f
#define PI pair<int, int>
typedef long long LL;
const int maxn = 10 + 1;
LL dp[2][1<<maxn];
int n, m;
void update(int f, int a, int b) {
	if(b & (1<<m)) dp[f][b^(1<<m)] += dp[1-f][a];
}
LL solve() {
	if(n < m) swap(n, m);
	memset(dp, 0, sizeof(dp));
	int f = 0;
	dp[0][(1<<m)-1] = 1; //边界
	for(int i = 0; i < n; ++i)
		for(int j = 0; j < m; ++j) {
			f ^= 1;
			memset(dp[f], 0, sizeof(dp[f]));
			for(int k = 0; k < (1 << m); ++k) {
				//不放
				update(f, k, k<<1);
				//横着放
				if(j && !(k&1)) update(f, k, (k<<1)^3);
				//竖着放
				if(i && !(k&(1<<m-1))) update(f, k, (k<<1)^(1<<m)^1);
			}
		}
	return dp[f][(1<<m)-1];
}
int main() {
	while(scanf("%d%d", &n, &m) == 2) {
		printf("%lld\n", solve());
	}
	return 0;
}

如有不当之处欢迎指出!

UVA - 11270 轮廓线DP的更多相关文章

  1. HDU1565 方格取数 &&uva 11270 轮廓线DP

    方格取数(1) Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Su ...

  2. UVA 11270 轮廓线

    题目链接: http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33787 题意: 用1*2或2*1的长条把n*m方格铺满的方案数. ...

  3. UVa 11270 铺放骨牌(轮廓线DP)

    https://vjudge.net/problem/UVA-11270 题意: 用1×2骨牌覆盖n×m棋牌,有多少种方法? 思路: 这道题目是典型的轮廓线DP题. 所谓轮廓线DP,就是以整行整列为状 ...

  4. uva 11270 - Tiling Dominoes(插头dp)

    题目链接:uva 11270 - Tiling Dominoes 题目大意:用1∗2木块将给出的n∗m大小的矩阵填满的方法总数. 解题思路:插头dp的裸题,dp[i][s]表示第i块位置.而且该位置相 ...

  5. 轮廓线DP POJ3254 && BZOJ 1087

    补了一发轮廓线DP,发现完全没有必要从右往左设置状态,自然一点: 5 6 7 8 9 1 2 3 4 如此设置轮廓线标号,转移的时候直接把当前j位改成0或者1就行了.注意多记录些信息对简化代码是很有帮 ...

  6. HDU4804 Campus Design 轮廓线dp

    跟上面那篇轮廓线dp是一样的,但是多了两个条件,一个是在原图上可能有些点是不能放的(即障碍),所以转移的时候要多一个判断color[i][j]是不是等于1什么的,另外一个是我们可以有多的1*1的骨牌, ...

  7. POJ2411 Mondriaan's Dream 轮廓线dp

    第一道轮廓线dp,因为不会轮廓线dp我们在南京区域赛的时候没有拿到银,可见知识点的欠缺是我薄弱的环节. 题目就是要你用1*2的多米诺骨排填充一个大小n*m(n,m<=11)的棋盘,问填满它有多少 ...

  8. [UOJ422][集训队作业2018]小Z的礼物——轮廓线DP+min-max容斥

    题目链接: [集训队作业2018]小Z的礼物 题目要求的就是最后一个喜欢的物品的期望得到时间. 根据$min-max$容斥可以知道$E(max(S))=\sum\limits_{T\subseteq ...

  9. 【UOJ#422】【集训队作业2018】小Z的礼物(min-max容斥,轮廓线dp)

    [UOJ#422][集训队作业2018]小Z的礼物(min-max容斥,轮廓线dp) 题面 UOJ 题解 毒瘤xzy,怎么能搬这种题当做WC模拟题QwQ 一开始开错题了,根本就不会做. 后来发现是每次 ...

随机推荐

  1. Linux实践篇--linux软件的安装,更新与卸载

    本文出处:http://www.cnblogs.com/lhj588/archive/2012/07/17/2595328.html,感谢作者分享. Linux常见的安装为tar,zip,gz,rpm ...

  2. Java的IO系统

     Java IO系统     "对语言设计人员来说,创建好的输入/输出系统是一项特别困难的任务."     由于存在大量不同的设计方案,所以该任务的困难性是很容易证明的.其中最大的 ...

  3. nodejs爬虫笔记(三)---爬取YouTube网站上的视频信息

    思路:通过笔记(二)中代理的设置,已经可以对YouTube的信息进行爬取了,这几天想着爬取网站下的视频信息.通过分析YouTube,发现可以从订阅号入手,先选择几个订阅号,然后爬取订阅号里面的视频分类 ...

  4. nagios中监测dns 227.7.128.68的网络状态

    [root@nhserver2 ~]# cd /usr/local/nagios/etc/objects [root@nhserver2 objects]# vim hosts_dns.cfgdefi ...

  5. 在nagios中使用nrpe自定义脚本

    nrpe的安装    tar xvfz nrpe-2.13.tar.gz cd nrpe-2.13 ./configure make all make install-plugin make inst ...

  6. Python笔记001-----简介及常用的库

    1.Python是一种解释性语言,大部分代码要比编译型语言(如C++,java等)运行要慢点多.2.对于高并发,多线程的应用程序而言,Python并不是理想语言,python有全局解释器锁(Globa ...

  7. 关于if和else嵌套—蛋疼

    嵌套使用的时候else if和else遵循就近原则,和上面最靠近该语句的if语句匹配,要把else if看成是一个整体.就这么干,这样好理解一点. 一个if...else if...else语句中可以 ...

  8. 浅探element-ui2组件源码之upload

    最近不小心更新了element-ui的版本,已经到了2.1.0,以前修改的源码都失效了. 于是重新尝试下面的指令重新修改: git clone https://github.com/ElemeFE/e ...

  9. CORS跨域请求之简单请求与非简单请求

    先来看一个例子 定义server01的项目,在路由表中添加一条路由记录 url(r'^getData.html$',views.get_data) 对应的视图函数 from django.shortc ...

  10. Tomcat学习

    一:项目默认部署路径: eclipse中,默认new一个server,项目默认会部署在:workspace\(工作空间)\.metadata\.plugins\org.eclipse.wst.serv ...