HDU 1010 Tempter of the Bone【DFS】
学习剪枝的第一篇@_@
学习别人的剪枝,一剪就是两天@_@----
参看的这篇--
http://blog.csdn.net/libin56842/article/details/8962512
自己的小体会--
奇偶剪枝可以举两个一般的例子
比如样例
S.X.
..X.
..XD
....
转化为所需要的步数
S 6 X 2
6 5 X 1
5 4 X D
4 3 2 1
可以看到步数为奇数的时候,所需要的时间也为奇数
步数为偶数的时候,需要的时间也为偶数(因为是一秒走一步)
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<math.h>
using namespace std;
int n,m,t,flag,di,dj,wall;
int dir[4][2]={{0,-1},{0,1},{-1,0},{1,0}};
char map[10][10]; void dfs(int si,int sj,int cnt)
{
int tem;
if(si<=0||sj<=0||si>n||sj>m)
return;
if(si==di&&sj==dj&&cnt==t) flag=1;
if(flag) return; tem=t-cnt-abs(di-si)-abs(dj-sj);
if(tem<0||tem%2)
return; for(int i=0;i<4;i++)
{
if(map[si+dir[i][0]][sj+dir[i][1]]!='X')
{
map[si+dir[i][0]][sj+dir[i][1]]='X';
dfs(si+dir[i][0],sj+dir[i][1],cnt+1);
map[si+dir[i][0]][sj+dir[i][1]]='.';
}
}
return;
}
int main()
{
int si,sj;
while(scanf("%d %d %d",&n,&m,&t)!=EOF&&n&&m&&t)
{
wall=0;
for(int i=1;i<=n;i++)
{
for(int j=1;j<=m;j++)
{
cin>>map[i][j];
if(map[i][j]=='S') {si=i;sj=j;}
else if(map[i][j]=='D') { di=i;dj=j;}
else if(map[i][j]=='X')
wall++;
}
} if(n*m-wall<=t)
{
printf("NO\n");
continue;
}
flag=0;
map[si][sj]='X';
dfs(si,sj,0);
if(flag)
printf("YES\n");
else
printf("NO\n");
}
}
HDU 1010 Tempter of the Bone【DFS】的更多相关文章
- HDU 1010 Tempter of the Bone【DFS经典题+奇偶剪枝详解】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010:Tempter of the Bone(DFS + 奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdoj 1010 Tempter of the Bone【dfs查找能否在规定步数时从起点到达终点】【奇偶剪枝】
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010 Tempter of the Bone(dfs)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010 Tempter of the Bone(dfs暴力)
Problem Description The doggie found a bone in an ancient maze, which fascinated him a lot. However, ...
- HDU 1010 Tempter of the Bone (DFS+剪枝)
题意:从S走到D,能不能恰好用T时间. 析:这个题时间是恰好,并不是少于T,所以用DFS来做,然后要剪枝,不然会TEL,我们这样剪枝,假设我们在(x,y),终点是(ex,ey), 那么从(x, y)到 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- hdu 1010 Tempter of the Bone 奇偶剪枝
如果所给的时间(步数) t 小于最短步数path,那么一定走不到. 若满足t>path.但是如果能在恰好 t 步的时候,走到出口处.那么(t-path)必须是二的倍数. 关于第二种方案的解释 ...
随机推荐
- Asp.net mvc中使用配置Unity
第一步:添加unity.mvc 第二步:在添加之后会在app_start中生成UnityConfig.cs,UnityMvcActivator.cs 第三步:使用 第四步:效果展示
- 清北集训Day3T1(转换)
这题可能是我与正解里的最近的一次了,可以还是sb的把正解叉了. 正解其实比较显然:因为$f(x)$只有81个取值,所以我们可以枚举$f(x)$,然后计算$x$,再判断$x$是否可以转化为$f(x)$ ...
- Unity脚本中可以引用的类型
Hierarchy(层级视图)面板里的对象,或者 Project(工程视图)里的Prefab.
- iproute2+tc notes
iproute2+tc notes The iproute2+tc package allows access to the variety of neat new networking featur ...
- 转载:常用 Git 命令清单
转载:常用 Git 命令清单 原文地址:http://www.ruanyifeng.com/blog/2015/12/git-cheat-sheet.html 作者: 阮一峰 我每天使用 Git , ...
- tcpsock for Golang
前记:本文所述的 tcpsock 库托管在 Github. Golang 中的 net 标准库已对 TCP 网络编程作了简洁(却很不简单)的封装,基本上,可直接通过引用其提供的相关接口开发简易的网络应 ...
- 【XSY2689】王子 - 网络流
复活!qwq 题目来源:2018冬令营模拟测试赛(九) 题意: [背景描述] 不是所有王子都会遇见自己的中关村,主公,公主. 从前有个王子姓王,王王子遇到了一位美丽的公主,她的名字当然是公公主 ...
- org.xml.sax.SAXParseException: Failed to read schema document 的原因分析与解决方法
现象: org.xml.sax.SAXParseException: schema_reference.4: Failed to read schema documen t 'http://www.s ...
- HDU 5763 Another Meaning (KMP/哈希+DP)
题目大意:给你两个串,一长一短,如果长串中某个子串和短串完全相同,则这个子串可以被替换成"#",求长串所有的表达形式....... 比如"hehehehe"和& ...
- [AtCoder Regular Contest 083] Bichrome Tree
树形DP. 每个点有两个属性:黑色点的权值和,白色点权值和,一个知道另一个也一定知道. 因为只要子树的和它相等的点得权值和不超过x[u],u点的权值总能将其补齐. 设计状态f[u]表示以u为根的子树, ...