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的棋盘 ...
随机推荐
- hdu 5023 线段树+位运算
主要考线段树的区间修改和区间查询,这里有一个问题就是这么把一个区间的多种颜色上传给父亲甚至祖先节点,在这里题目告诉我们最多30颜色,那么我们可以把这30中颜色用二进制储存和传给祖先节点,二进制的每一位 ...
- LightOJ - 1030 期望+dp
题目链接:https://vjudge.net/problem/25907/origin 一个山洞,里面有有1到n个位置,每个位置都有一定的金币,你有一个六面的骰子,一开始你在1,每次摇到了哪个数就往 ...
- TZOJ 1321 Girls and Boys(匈牙利最大独立集)
描述 the second year of the university somebody started a study on the romantic relations between the ...
- 分布式大数据多维数据分析(olap)引擎kylin[转]
Apache Kylin是一个开源的分布式分析引擎,提供Hadoop之上的SQL查询接口及多维分析(OLAP)能力以支持超大规模数据,最初由eBay 开发并贡献至开源社区.它能在亚秒内查询巨大的Hiv ...
- jQuery跳转到页面指定位置
@参考博客 var t = $("#id").offset().top;// 获取需要跳转到标签的top值 //$(window).scrollTop(t);// 跳转到指定位置 ...
- GridView中CheckBox翻页记住选项
<asp:GridView ID="gvYwAssign" runat="server" AutoGenerateColumns="False& ...
- 配置eclipse+SDK+ADT开发环境
第一步:配置jdk和eclipse环境(已完成): 第二步:ADT配置:依次点击菜单栏:help -> Install new software -> Add -> Local... ...
- input 与raw_input的区别
input只能输入数字 raw_input 既可以输入数字也可以输入字符串 >>> input("input you name:") input you name ...
- [z]eclipase优化
eclipse启动优化,终于不那么卡了! 网上找了好多都是myEclipse的优化的,跟eclipse有点区别,找了很多方法还是不能让这个eclipse(Version: Kepler Release ...
- VSCode一直弹框错误Linter pylint is not installed
确保已经安装Python编译环境 点击下图位置(这个是我已经安装过后的文字,原本显示“搜索Python”字样) 点击后显示如下,点击安装 然后出现一大坨命令 最终出现“Successfully ins ...