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 ...
随机推荐
- java 读取excel 将数据插入到数据库
import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import java.sql.Con ...
- hdu_5813_Elegant Construction(xjb搞)
题目链接:hdu_5813_Elegant Construction 题意: 给你n个点,每个点要可以到达ai个点,可以直接可以间接,不能有环,问是否可行,如果可行就任选一种方式连接,并输出连接的边数 ...
- Centos虚拟机安装分区分配
i 安装hadoop虚拟机
- LeetCode OJ 64. Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...
- SharePoint2013 Excel导出好的代码
C#Excel操作类ExcelHelper.cs 来源:http://www.hellocsharp.com/article/67.aspx C#源码世界 发布于: 2014-09-12 使用本类之前 ...
- java的string.split()分割特殊字符时注意点
[1]单个符号作为分隔符 String address="上海|上海市|闵行区|吴中路"; String[] splitAddress=address.s ...
- 简单的javasrcipt选项卡
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <meta char ...
- CentOS中文件夹基本操作命令
摘自:http://www.centoscn.com/CentOS/help/2013/1024/1967.html 文件(夹)查看类命令 ls--显示指定目录下内容 说明:ls 显示结果以不同的颜色 ...
- CentOS 7 多网卡绑定
根据官方文档Red_Hat_Enterprise_Linux-7-Networking_Guide-en-US用nmcli做起来还是相当容易的.下面把俺的步骤贴下. 1.查看目前网卡的名称和状态.#n ...
- input时间输入框小解
date 年月日 month 年月 week 年周(ios上不可用,android部分会显示当前是第几周) time 时分(ios不显示时/分的字样) datetime 为一输入框,基本 ...