HDU1693 Eat the Trees(zerojudge a228)
传送门:
https://zerojudge.tw/ShowProblem?problemid=a228
http://acm.hdu.edu.cn/showproblem.php?pid=1693
【题解】
插头dp第一题(难以置信我高中oi没有写过23333)
方程很简单,自己推一推插头的地方的连通性即可
放几张图跑了
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const int M = + , MAX_STATUS = ( << ) + ;
const int mod = 1e9 + ; int n, m, a[M][M], tCase = ;
ll f[M][M][MAX_STATUS]; inline void sol() {
cin >> n >> m;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
scanf("%d", &a[i][j]);
int STATUS_SIZE = ( << m+) - ;
int STATUS_SIZE_T = ( << m) - ;
f[][m][] = ;
for (int i=; i<=n; ++i) {
for (int sta=; sta<=STATUS_SIZE_T; ++sta) f[i][][sta << ] = f[i-][m][sta];
for (int j=; j<=m; ++j)
for (int sta=; sta<=STATUS_SIZE; ++sta) {
bool cur1 = (sta & ( << j-)), cur2 = (sta & ( << j));
if(a[i][j] == ) {
if(cur1 && cur2) f[i][j][sta] = f[i][j-][sta - ( << j-) - ( << j)];
else if(cur1 ^ cur2) {
int STA = (sta | ( << j-) | ( << j));
f[i][j][sta] = f[i][j-][STA - ( << j-)] + f[i][j-][STA - ( << j)];
} else f[i][j][sta] = f[i][j-][sta | ( << j-) | ( << j)];
} else {
if(!cur1 && !cur2) f[i][j][sta] = f[i][j-][sta];
else f[i][j][sta] = ;
}
}
}
cout << "Case " << ++tCase << ": There are " << f[n][m][] << " ways to eat the trees.\n";
} int main() {
int T;
cin >> T;
while(T--) sol();
return ;
}
# include <stdio.h>
# include <string.h>
# include <iostream>
# include <algorithm> using namespace std; typedef long long ll;
typedef unsigned long long ull;
typedef long double ld; const int M = + , MAX_STATUS = ( << ) + ;
const int mod = 1e9 + ; int n, m, a[M][M], tCase = ;
int f[M][M][MAX_STATUS]; inline void sol() {
cin >> n >> m;
for (int i=; i<=n; ++i)
for (int j=; j<=m; ++j)
scanf("%d", &a[i][j]);
int STATUS_SIZE = ( << m+) - ;
int STATUS_SIZE_T = ( << m) - ;
f[][m][] = ;
for (int i=; i<=n; ++i) {
for (int sta=; sta<=STATUS_SIZE_T; ++sta) f[i][][sta << ] = f[i-][m][sta];
for (int j=; j<=m; ++j)
for (int sta=; sta<=STATUS_SIZE; ++sta) {
bool cur1 = (sta & ( << j-)), cur2 = (sta & ( << j));
if(a[i][j] == ) {
if(cur1 && cur2) f[i][j][sta] = f[i][j-][sta - ( << j-) - ( << j)];
else if(cur1 ^ cur2) {
int STA = (sta | ( << j-) | ( << j));
f[i][j][sta] = f[i][j-][STA - ( << j-)] + f[i][j-][STA - ( << j)];
if(f[i][j][sta] >= mod) f[i][j][sta] -= mod;
} else f[i][j][sta] = f[i][j-][sta | ( << j-) | ( << j)];
} else {
if(!cur1 && !cur2) f[i][j][sta] = f[i][j-][sta];
else f[i][j][sta] = ;
}
}
}
cout << "Case " << ++tCase << ": " << f[n][m][] << endl;
} int main() {
int T;
cin >> T;
while(T--) sol();
return ;
}
上面hdu,下面zerojudge
HDU1693 Eat the Trees(zerojudge a228)的更多相关文章
- 2019.01.23 hdu1693 Eat the Trees(轮廓线dp)
传送门 题意简述:给一个有障碍的网格图,问用若干个不相交的回路覆盖所有非障碍格子的方案数. 思路:轮廓线dpdpdp的模板题. 同样是讨论插头的情况,只不过没有前一道题复杂,不懂的看代码吧. 代码: ...
- [Hdu1693]Eat the Trees(插头DP)
Description 题意:在n*m(1<=N, M<=11 )的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少种方法. Solution 插头DP ...
- 【HDU1693】Eat the Trees(插头dp)
[HDU1693]Eat the Trees(插头dp) 题面 HDU Vjudge 大概就是网格图上有些点不能走,现在要找到若干条不相交的哈密顿回路使得所有格子都恰好被走过一遍. 题解 这题的弱化版 ...
- Eat the Trees(hdu 1693)
题意:在n*m的矩阵中,有些格子有树,没有树的格子不能到达,找一条或多条回路,吃完所有的树,求有多少中方法. 第一道真正意义上的插头DP,可参考陈丹琦的<基于连通性状态压缩的动态规划问题> ...
- HDU 1693 Eat the Trees (插头DP)
题意:给一个n*m的矩阵,为1时代表空格子,为0时代表障碍格子,问如果不经过障碍格子,可以画一至多个圆的话,有多少种方案?(n<12,m<12) 思路: 这题不需要用到最小表示法以及括号表 ...
- HDU1693 Eat the Trees —— 插头DP
题目链接:https://vjudge.net/problem/HDU-1693 Eat the Trees Time Limit: 4000/2000 MS (Java/Others) Mem ...
- HDU 1693 Eat the Trees(插头DP、棋盘哈密顿回路数)+ URAL 1519 Formula 1(插头DP、棋盘哈密顿单回路数)
插头DP基础题的样子...输入N,M<=11,以及N*M的01矩阵,0(1)表示有(无)障碍物.输出哈密顿回路(可以多回路)方案数... 看了个ppt,画了下图...感觉还是挺有效的... 参考 ...
- HDU 1693 Eat the Trees(插头DP,入门题)
Problem Description Most of us know that in the game called DotA(Defense of the Ancient), Pudge is a ...
- hdu1693 Eat the Trees [插头DP经典例题]
想当初,我听见大佬们谈起插头DP时,觉得插头DP是个神仙的东西. 某大佬:"考场见到插头DP,直接弃疗." 现在,我终于懂了他们为什么这么说了. 因为-- 插头DP很毒瘤! 为什么 ...
随机推荐
- Load generator连接失败的解决办法!(转)
环境:1.loadrunner control 一台物理机(win2008r2) 2.loadrunner agent 两台物理机(win2008r2) 问题:loadrunner control 连 ...
- windows多线程(七) 事件event
前面说的互斥量Mutex与关键段CriticalSection都不能实现线程的同步,只能实现互斥,接下来我们用时间event就可以实现线程的同步了,事件也是一个内核对象. 一.相关函数说明 (一) 创 ...
- bing 搜索引擎 无法访问 bug
bing 搜索引擎 无法访问 bug 自从 Google 不好正常使用以后, 一直在使用 bing, 今天突然就 无法访问了,怎么回事?被黑了? ... loading https://cn.bing ...
- linux 关机、重启
一.重启命令:1.reboot2.shutdown -r now 立刻重启(root用户使用)3.shutdown -r 10 过10分钟自动重启(root用户使用) 4.shutdown -r 20 ...
- 第217天:深入理解Angular双向数据绑定的原理
一.理解angular双向数据绑定 双向绑定是新的前端框架中频繁出现的一个新词汇,也是mvvm的核心原理.angularjs五条核心信念中的数据驱动,便是由双向绑定进行完成. 那么什么是双向绑定,下面 ...
- MySQL 双主问题集
最近试用MySQL高可用方案,需要配MySQL双主,对期间遇到的问题做下记录. 1.导出锁表问题 mysqldump 命令增加参数 --skip-opt -q 可避免导出时锁表: 2.导出\导入所有数 ...
- P1198 [JSOI2008]最大数
题目描述 现在请求你维护一个数列,要求提供以下两种操作: 1. 查询操作. 语法:Q L 功能:查询当前数列中末尾L个数中的最大的数,并输出这个数的值. 限制:L不超过当前数列的长度.(L>0) ...
- 【bzoj2594】 Wc2006—水管局长数据加强版
http://www.lydsy.com/JudgeOnline/problem.php?id=2594 (题目链接) 题意 给出一个带边权的无向简单,要求维护两个操作,删除${u,v}$之间的连边: ...
- Python OS模块操作文件和目录
#-*-coding:utf-8-*- import os import shutil ###############OS模块############## #获得当前python脚本的工作目录 os. ...
- 设置nginx日志滚动
需求:设置nginx每天凌晨12点轮转,系统版本为debian7,nginx版本为tengine2.2.0 1.修改logrotate主配置文件,打开压缩和以时间为后缀命名 # vim /etc/lo ...