HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)
需要剪枝否则会超时,然后就是基本的深搜了
#include<cstdio>
#include<stdio.h>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<vector>
#include<queue>
#define INF 0x3f3f3f3f
#define MAX 1005 using namespace std; char Map[MAX][MAX]; int time,n,m,sx,sy,ex,ey,v[][]={{,},{,},{-,},{,-}},ok; bool check(int x,int y)
{
if(x>= && x<n && y>= && y<m && Map[x][y]!='X')
return true;
return false;
} void DFS(int x,int y,int step)
{
if(x==ex && y==ey && step==time)
{
ok=;
return;
}
else if(step >= time || ok)
return;
for(int i=;i<;i++)
{
int new_x=x+v[i][];
int new_y=y+v[i][];
if(check(new_x,new_y))
{
Map[new_x][new_y]='X';
DFS(new_x,new_y,step+);
Map[new_x][new_y]='.';
}
}
} int main()
{
while(scanf("%d%d%d",&n,&m,&time),n+m+time)
{
ok=;
for(int i=;i<n;i++)
scanf("%s",Map[i]);
for(int i=;i<n;i++)
{
for(int j=;j<m;j++)
{
if(Map[i][j]=='S')
{
sx=i;
sy=j;
}
if(Map[i][j]=='D')
{
ex=i;
ey=j;
}
}
}
int k1=abs(sx-ex);
int k2=abs(sy-ey);
if((time-(k1+k2))%)//奇偶剪纸
{
printf("NO\n");
continue;
}
if(sx==ex && sy==ey)
{
printf("YES\n");
continue;
}
Map[sx][sy]='X';
DFS(sx,sy,);
if(ok)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
HDU 1010 Tempter of the Bone DFS(奇偶剪枝优化)的更多相关文章
- HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...
- 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+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)
http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...
- HDU 1010 Tempter of the Bone --- DFS
HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...
- HDU 1010 Tempter of the Bone (DFS+可行性奇偶剪枝)
<题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...
- hdu 1010 Tempter of the Bone 深搜+剪枝
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- Tempter of the Bone(dfs奇偶剪枝)
Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Othe ...
- M - Tempter of the Bone(DFS,奇偶剪枝)
M - Tempter of the Bone Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & % ...
- (step4.3.1) hdu 1010(Tempter of the Bone——DFS)
题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...
随机推荐
- linux文件系统拓展属性
在研究GlusterFS中,发现GlusterFS使用了文件系统的Extended Attributes,中文可以称之为文件系统扩展属性.由于资料比较少,中文资料更少,因此把记录几点Extended ...
- js提交form表单
<form action="/Enterprise/member" id="sendinviteid" method="post"&g ...
- ElasticSearch(1)-入门
下一篇 Elastic Search基础(2) 相关文档: Gitbook[中文未完整]: http://learnes.net/ Gitbook[英文完整]:https://allen8807.gi ...
- Rational Rose 2003 逆向工程转换C++ / VC++ 6.0源代码成UML类图
目录 1.安装&破解Rational Rose 2003 1.1 安装Rose 2003 1.2 破解Rose 2003 1.3运行出错“没有找到suite objects.dl” 2. Ra ...
- 怎么查看window7的.net framework的版本
第一步.打开控制面板,在大图标查看方式下,点击“程序和功能” 第二步.在程序和功能界面,点击左侧“打开或关闭Windows功能” 第三步.在打开或关闭Windows功能界面,通过拖动滚动条的方式,找到 ...
- JPA 系列教程12-复合主键-2个@Id+@IdClass
复合主键 指多个主键联合形成一个主键组合 需求产生 比如航线一般是由出发地及目的地确定,如果要确定唯一的航线就可以用出发地和目的地一起来表示 ddl语句 同复合主键-2个@Id一样 Airline p ...
- Myeclipse安装jbpm6
1.下载jbpm-6.3.0.Final-installer-full.zip解压此文件 2.在myeclipse2013安装路径(F:\tool\myeclipse2013)下新建文件夹jbpm6- ...
- Webdriver如何解决页面元素过期:org.openqa.selenium.StaleElementReferenceException: Element not found in the cache - perhaps the page has changed since it was looked up
当运行Webdriver时抛出如下异常:org.openqa.selenium.StaleElementReferenceException: Element not found in the cac ...
- sfs - django start from scratch
[TOC] Launch with code git spreading is obsolte lwc Installation Path D:\PythonWebSW\Django-1.5.5 ad ...
- 学习笔记——备忘录模式Memento
备忘录模式,可以将当前状态保存,并随时恢复. Originator存在状态state,当需要保存此状态时,通过CreateMemento创建一个备忘录对象Memento保存此状态:而需要恢复相应状态时 ...