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的棋盘 ...
随机推荐
- 快速了解和使用Photon Server
https://blog.csdn.net/qq_36565626/article/details/78710787
- windows安装ssh工具opensssh
本篇教程将告诉你如何在Windows 10设备上启用SSH,让您可以通过命令提示符连接到远程服务器 工具/原料 首先你需要下载windows版本的OpenSSH, 本教程以7.2p1-1版本为例 ...
- Linq 查询 List集合
总是听到身边的同事说起Linq ,知道上学的时候学过,可是自从毕业之后就再也没用过,总觉得是很牛的技能 ,可是当自己真正学会用的时候才发现,我去,So easy .废话不多说直接上代码吧 var li ...
- TableView中Label自适应高度
//Xcode6.3以后label自适应需要添加两个属性 _tableView.rowHeight = UITableViewAutomaticDimension; //给予预计行高 _tableVi ...
- Linux 下SHELL脚本自动同步文件
#!/bin/bash expect <<EOF set timeout spawn rsync -avz root@192.168.10.57:/var/www/html/manage_ ...
- 运行./build.sh出现错误:bash: ./build.sh: Permission denied
原因:文件为只读,或者用户没有权限. 修改方法: 运行命令: chmod 777 build.sh
- JS获取Dropdownlist选中值
var dropDownList = document.getElementById("ddl_sheng"); //获取DropDownList控件 var dropDownLi ...
- ----转载----【前端工具】Chrome 扩展程序的开发与发布 -- 手把手教你开发扩展程序
关于 chrome 扩展的文章,很久之前也写过一篇.清除页面广告?身为前端,自己做一款简易的chrome扩展吧. 本篇文章重在分享一些制作扩展的过程中比较重要的知识及难点. 什么是 chrome 扩展 ...
- Charles抓取https包
Android: 1.若滑动解锁,请先设置屏幕锁: 2.然后浏览器输入Charlesproxy.com/getssl,安装证书,出现安装证书提示,随便打个名称 比如Android,选择WLAN(这里A ...
- Android开发之ListView设置隔行变色
public class HLCheckAdapter extends BaseAdapter { private List<HuoLiang> list; private Context ...