需要剪枝否则会超时,然后就是基本的深搜了

#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(奇偶剪枝优化)的更多相关文章

  1. HDU 1010 Tempter of the Bone(DFS+奇偶剪枝)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1010 题目大意: 输入 n m t,生成 n*m 矩阵,矩阵元素由 ‘.’ 'S' 'D' 'X' 四 ...

  2. 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 ...

  3. hdu - 1010 Tempter of the Bone (dfs+奇偶性剪枝) && hdu-1015 Safecracker(简单搜索)

    http://acm.hdu.edu.cn/showproblem.php?pid=1010 这题就是问能不能在t时刻走到门口,不能用bfs的原因大概是可能不一定是最短路路径吧. 但是这题要过除了细心 ...

  4. HDU 1010 Tempter of the Bone --- DFS

    HDU 1010 题目大意:给定你起点S,和终点D,X为墙不可走,问你是否能在 T 时刻恰好到达终点D. 参考: 奇偶剪枝 奇偶剪枝简单解释: 在一个只能往X.Y方向走的方格上,从起点到终点的最短步数 ...

  5. HDU 1010 Tempter of the Bone (DFS+可行性奇偶剪枝)

    <题目链接> 题目大意:一个迷宫,给定一个起点和终点,以及一些障碍物,所有的点走过一次后就不能再走(该点会下陷).现在问你,是否能从起点在时间恰好为t的时候走到终点. 解题分析:本题恰好要 ...

  6. hdu 1010 Tempter of the Bone 深搜+剪枝

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  7. Tempter of the Bone(dfs奇偶剪枝)

    Tempter of the Bone Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Othe ...

  8. M - Tempter of the Bone(DFS,奇偶剪枝)

    M - Tempter of the Bone Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  9. (step4.3.1) hdu 1010(Tempter of the Bone——DFS)

    题目大意:输入三个整数N,M,T.在接下来的N行.M列会有一系列的字符.其中S表示起点,D表示终点. .表示路 . X表示墙...问狗能有在T秒时到达D.如果能输出YES, 否则输出NO 解题思路:D ...

随机推荐

  1. 部署WEB应用的三种方式[转]

    一.基本部署 Tomcat安装目录下有一个webapps目录,该目录存放所有的WEB应用程序,Tomcat会自动管理该目录下的所有WEB应用.因此,最简单的部署方式就是将要部署的WEB应用直接拷贝到T ...

  2. Linux入门(五)linux服务器文件远程管理

     1 使用filezila远程管理linux服务器文件 filezila下载地址:https://filezilla-project.org/ filezila默认只能登录普通用户,如果想要root用 ...

  3. createElement创建

    定义和用法 createElement() 方法可创建元素节点. 此方法可返回一个 Element 对象. <script type="text/javascript"> ...

  4. apache 配置

    apache 2.4.9 httpd-vhosts.conf部分 <VirtualHost *:81>             //配置端口 DocumentRoot "E:/H ...

  5. Marble 添加自定义Layer

    #include <marble/MarbleWidget.h> #include <marble/MarbleMap.h> #include <marble/Marbl ...

  6. stb_image读取图片数据

    #include <iostream> #include <fstream> #include <stbi/stb_image.h> const unsigned ...

  7. delphi中nil、null、UnAssigned区别

    nil:空指针,空地址,对象也是指针,所以可以object := nil;null:null是一个未定义值的变量,既不是0也不代表空字符串,它是未定义的.http://www.delphibasics ...

  8. javascript 中的console.log的作用

    主要是方便你调式javascript用的.你可以看到你在页面中输出的内容. 相比alert他的优点是: 他能看到结构话的东西,如果是alert,淡出一个对象就是[object object],但是co ...

  9. Matlab - 矩阵基本操作

    1. 矩阵的输入 右值是用方括号表示: , 逗号或空格分隔元素     ; 分号分隔行 >> A = [-, ; , ] A = - 2. 矩阵的加减 >> C = A + B ...

  10. UNIX基础--权限

    权限 Permissions FreeBSD使用传统的UNIX®系统的基本权限.在UNIX®系统中,基本权限分配了三种访问类型:读.写.执行.权限可以用字母r.w.x表示:也可以用二进制数表示,按rw ...