传送门

题意简述:给一个有障碍的网格图,问用若干个不相交的回路覆盖所有非障碍格子的方案数。


思路:轮廓线dpdpdp的模板题。

同样是讨论插头的情况,只不过没有前一道题复杂,不懂的看代码吧。

代码:

#include<bits/stdc++.h>
#include<tr1/unordered_map>
#define ri register int
using namespace std;
using namespace tr1;
typedef long long ll;
int n,m,zx=-1,zy=-1,cur;
bool mp[15][15];
char s[15];
ll ans=0;
const int mod=1e6+7;
struct Statement{
	int tot,idx[mod],sta[mod];
	ll num[mod];
	inline void clear(){memset(idx,-1,sizeof(idx)),tot=0;}
	inline void insert(int stat,ll nume){
		int pos=stat%mod;
		if(!pos)++pos;
		while(~idx[pos]&&sta[idx[pos]]!=stat)pos=pos==mod-1?1:pos+1;
		if(~idx[pos])num[idx[pos]]+=nume;
		else sta[idx[pos]=++tot]=stat,num[tot]=nume;
	}
}f[2];
inline int getbit(int x,int p){return (x>>(p-1))&1;}
inline void update(int&x,int p,int v){x^=(v^getbit(x,p))<<(p-1);}
inline void solve(){
	f[cur=0].clear(),f[cur].insert(0,1);
	for(ri i=1;i<=n;++i){
		for(ri j=1;j<=m;++j){
			cur^=1,f[cur].clear();
			for(ri tt=1;tt<=f[cur^1].tot;++tt){
				int stat=f[cur^1].sta[tt],p=getbit(stat,j),q=getbit(stat,j+1);
				ll dpnum=f[cur^1].num[tt];
				if(!mp[i][j]){if(!(p+q))f[cur].insert(stat,dpnum);continue;}
				if(!(p+q)){
					if(mp[i][j+1]&&mp[i+1][j])update(stat,j,1),update(stat,j+1,1),f[cur].insert(stat,dpnum);
					continue;
				}
				if(!p){
					if(mp[i][j+1])f[cur].insert(stat,dpnum);
					if(mp[i+1][j])update(stat,j,1),update(stat,j+1,0),f[cur].insert(stat,dpnum);
					continue;
				}
				if(!q){
					if(mp[i+1][j])f[cur].insert(stat,dpnum);
					if(mp[i][j+1])update(stat,j,0),update(stat,j+1,1),f[cur].insert(stat,dpnum);
					continue;
				}
				update(stat,j,0),update(stat,j+1,0),f[cur].insert(stat,dpnum);
				if(i==zx&&j==zy)ans+=dpnum;
			}
		}
		for(ri j=1;j<=f[cur].tot;++j)f[cur].sta[j]<<=1;
	}
}
inline int read(){
	int ans=0;
	char ch=getchar();
	while(!isdigit(ch))ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch^48),ch=getchar();
	return ans;
}
int main(){
	for(ri up=read(),tt=1;tt<=up;++tt){
		n=read(),m=read(),zx=zy=-1,memset(mp,0,sizeof(mp));
		for(ri i=1;i<=n;++i)for(ri j=1;j<=m;++j)if(mp[i][j]=read())zx=i,zy=j;
		if(zx==-1)puts("0");
		else ans=0,solve(),cout<<"Case "<<tt<<": There are "<<ans<<" ways to eat the trees.\n";
	}
	return 0;
}

2019.01.23 hdu1693 Eat the Trees(轮廓线dp)的更多相关文章

  1. 2019.01.23 ural1519 Formula 1(轮廓线dp)

    传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...

  2. HDU1693 Eat the Trees —— 插头DP

    题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others)    Mem ...

  3. HDU1693 Eat the Trees 插头dp

    原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...

  4. hdu1693 Eat the Trees [插头DP经典例题]

    想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...

  5. 2019.01.24 NOIP训练 旅行(轮廓线dp)

    传送门 题意简述: 给一个n∗mn*mn∗m的有障碍的网格图,问你从左上角走到左下角并覆盖所有可行格子的路径条数. 思路: 路径不是很好算. 将图改造一下,在最前面添两列,第一列全部能通过,第二列只有 ...

  6. hdu1693 Eat the Trees 【插头dp】

    题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...

  7. [Hdu1693]Eat the Trees(插头DP)

    Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...

  8. HDU1693 Eat the Trees(zerojudge a228)

    传送门: https://zerojudge.tw/ShowProblem?problemid=a228 http://acm.hdu.edu.cn/showproblem.php?pid=1693 ...

  9. HDU 1693 Eat the Trees(插头DP)

    题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...

随机推荐

  1. C++求图任意两点间的所有路径

    基于连通图,邻接矩阵实现的图,非递归实现. 算法思想: 设置两个标志位,①该顶点是否入栈,②与该顶点相邻的顶点是否已经访问. A 将始点标志位①置1,将其入栈 B 查看栈顶节点V在图中,有没有可以到达 ...

  2. http://ctf.bugku.com/challenges#Easy_Re

      今天做一道逆向题,开心,见证了自己汇编的用途.     首先看它是否加壳? 1.加壳检测   是vc编程的,没有加壳,可以愉快地分析了.   2.分析程序,找到flag.   首先运行一下子程序, ...

  3. H5外部浏览器直接调起微信——通过url协议 weixin:// 判断是否安装微信及启动微信

    前言: h5分享到微信,h5使用微信支付这些功能,都需要先判断是否安装微信客户端,如果已安装就启动微信,如果没有安装微信,就提示用户前去安装. 我们可以通过访问微信提供的URL协议(weixin:// ...

  4. PTA 7-2 符号配对(栈模拟)

    请编写程序检查C语言源程序中下列符号是否配对:/*与*/.(与).[与].{与}. 输入格式: 输入为一个C语言源程序.当读到某一行中只有一个句点.和一个回车的时候,标志着输入结束.程序中需要检查配对 ...

  5. swift4.2 打印devicetoken

    import UIKit import UserNotifications @UIApplicationMain class AppDelegate: UIResponder, UIApplicati ...

  6. iOS工程中创建pch文件

    1.新建pch类文件 2.在工程配置中,Build Setting 下搜索"pre"寻找Apple LLVM6.1 - Language下的 Preflx Header 3.点开P ...

  7. Js或 Activex 控件调用打印预览等操作

    <input value="打印" type="button" onclick="javascript:window.print()" ...

  8. node.js中npm包管理工具

    现在安装node.js,默认就会帮我们装上了npm包管理工具,npm主要用来下载,安装,管理第三方模块. 创建一个包描述文件: npm init [-y] 查看包的信息 npm info <pa ...

  9. 操作系统的发展史 day36

    什么是操作系统       可能很多人都会说,我们平时装的windows7 windows10都是操作系统,没错,他们都是操作系统.还有没有其他的? 想想我们使用的手机,Google公司的Androi ...

  10. Oracle_PL/SQL(6) 触发器(序列、视图)

    序列1.创建序列create sequence seq_alog start with 1 increment by 1 maxvalue 999999999999999999999999999 mi ...