2019.01.23 hdu1693 Eat the Trees(轮廓线dp)
传送门
题意简述:给一个有障碍的网格图,问用若干个不相交的回路覆盖所有非障碍格子的方案数。
思路:轮廓线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)的更多相关文章
- 2019.01.23 ural1519 Formula 1(轮廓线dp)
传送门 轮廓线dpdpdp模板题. 题意简述:给一个放有障碍的网格图,问有多少种方法能使所有非障碍格子都在同一条哈密顿回路上面. 考虑用括号序列的写法来状压这个轮廓线. 用000表示没有插头,111表 ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- HDU1693 Eat the Trees 插头dp
原文链接http://www.cnblogs.com/zhouzhendong/p/8433484.html 题目传送门 - HDU1693 题意概括 多回路经过所有格子的方案数. 做法 最基础的插头 ...
- hdu1693 Eat the Trees [插头DP经典例题]
想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...
- 2019.01.24 NOIP训练 旅行(轮廓线dp)
传送门 题意简述: 给一个n∗mn*mn∗m的有障碍的网格图,问你从左上角走到左下角并覆盖所有可行格子的路径条数. 思路: 路径不是很好算. 将图改造一下,在最前面添两列,第一列全部能通过,第二列只有 ...
- hdu1693 Eat the Trees 【插头dp】
题目链接 hdu1693 题解 插头\(dp\) 特点:范围小,网格图,连通性 轮廓线:已决策点和未决策点的分界线 插头:存在于网格之间,表示着网格建的信息,此题中表示两个网格间是否连边 状态表示:当 ...
- [Hdu1693]Eat the Trees(插头DP)
Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...
- HDU1693 Eat the Trees(zerojudge a228)
传送门: https://zerojudge.tw/ShowProblem?problemid=a228 http://acm.hdu.edu.cn/showproblem.php?pid=1693 ...
- HDU 1693 Eat the Trees(插头DP)
题目链接 USACO 第6章,第一题是一个插头DP,无奈啊.从头看起,看了好久的陈丹琦的论文,表示木看懂... 大体知道思路之后,还是无法实现代码.. 此题是插头DP最最简单的一个,在一个n*m的棋盘 ...
随机推荐
- Python+Selenium学习--打印当前页面的title及url
场景 测试中,访问1个页面然后判断其title是否符合预期是很常见的1个用例,所谓用例不够,title来凑就是这个道理.更具体一点,假设1个页面的title应该是'hello world', 那么可以 ...
- SSH和SSM的区别
一怒成仙 博客园 首页 新随笔 联系 管理 订阅 随笔- 54 文章- 1 评论- 0 SSH(Struts,Spring,Hibernate)和SSM(SpringMVC,Spring,M ...
- stm32 map文件的分析
相信有较大项目开发经验的朋友都曾遇到内存溢出的问题,那么大家都是如何分析这类问题的呢?大家遇到HardFault_Handler 有对map分析过吗? 首先讲述一下关于map在MDK-ARM中的配置. ...
- 项目总结12:bootstrap-select下拉框模糊搜索
bootstrap select下拉框模糊搜索 关键字 bootstrap-select 下拉框模糊搜索 正文(直接上源码) <%@ page language="java" ...
- [leetcode]161. One Edit Distance编辑步数为一
Given two strings s and t, determine if they are both one edit distance apart. Note: There are 3 pos ...
- HTTP协议介绍(POST、GET、Content-Type)
什么是HTTP?超文本传输协议(HyperText Transfer Protocol -- HTTP)是一个设计来使客户端和服务器顺利进行通讯的协议.HTTP/1.1 协议规定的 HTTP 请求方法 ...
- NPOI创建DOCX常用操作
1. 创建文档 XWPFDocument m_Docx = new XWPFDocument(); 2. 页面设置 //1‘=1440twip=25.4mm=72pt(磅point)=96px(像 ...
- 遇到返回键会退到页面的问题(window.location)
我的需求是a全局列表页->b展示列表页->c新增页(编辑页)我从b展示列表页,通过编辑进入c编辑页,保存回到b展示列表页. 重,我的b展示列表页,返回要返回的其实是a全局列表页*使用rep ...
- java的几个日志框架log4j、logback、common-logging
开发工作中每个系统都需要记录日志,常见的日志工具有log4j(用的最多),slf4j,commons-loging,以及最近比较流行的logback 以前只是在项目中用log4j,更多的是参考下配置文 ...
- Oracle_SQL(7) 复杂查询
1.rownum 伪列<,<=select * from emp where rownum<5; 取工资前3名的人员 select * from (select * from emp ...