HDOJ--1010题C++
#include<iostream>
#include<utility>
#define INF 10000
using namespace std;
char maze[100][7];
int d[100][7];
int n,m,t,start_i,start_j,end_i,end_j;
int dx[]= {0,1,0,-1},dy[]= {1,0,-1,0};
bool dfs(int i,int j);
int main()
{
while(cin>>n>>m>>t && n &&m
&& t)
{
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
{
cin>>maze[i][j];
if(maze[i][j]=='S')
{
start_i=i;
start_j=j;
}
if(maze[i][j]=='D')
{
end_i=i;
end_j=j;
}
}
for(int i=0; i<n; i++)
for(int j=0; j<m; j++)
d[i][j]=INF;
d[start_i][start_j]=0;
if(dfs(start_i,start_j))
cout<<"YES"<<endl;
else
cout<<"NO"<<endl;
}
return 0;
}
bool dfs(int i,int j)
{
if(i==end_i && j==end_j)
{
if(d[i][j]==t)
{
d[i][j]=INF;
return true;
}
else
{
d[i][j]=INF;
return false;
}
}
else
{
for(int k=0; k<4; k++)
{
int nx=dx[k]+i,ny=dy[k]+j;
if( nx>=0 &&nx < n &&ny>=0 && ny<m && (d[nx][ny]==INF) &&((maze[nx][ny]=='.')||(maze[nx][ny]=='D')))
{
if(dfs(nx,ny))
{
d[nx][ny]=INF;
return true;
}
else
d[nx][ny]=INF;
}
}
d[i][j]=INF;
return false;
}
}
HDOJ--1010题C++的更多相关文章
- HDOJ.1010 Tempter of the Bone (DFS)
Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...
- HDU 4768 Flyer (2013长春网络赛1010题,二分)
Flyer Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submi ...
- HDU 4664 Triangulation(2013多校6 1010题,博弈)
Triangulation Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tot ...
- HDOJ 1004题 Let the Balloon Rise strcmp()函数
Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...
- HDOJ 1312题Red and Black
Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...
- HDOJ 1013题Digital Roots 大数,9余数定理
Problem Description The digital root of a positive integer is found by summing the digits of the int ...
- 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 4747 Mex (2013杭州网络赛1010题,线段树)
Mex Time Limit: 15000/5000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submis ...
- HDU 4705 Y (2013多校10,1010题,简单树形DP)
Y Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...
- HDU 4685 Prince and Princess (2013多校8 1010题 二分匹配+强连通)
Prince and Princess Time Limit: 6000/3000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Othe ...
随机推荐
- VS2010配置WTL
1.首先去下载WTL 地址:http://wtl.svn.sourceforge.net/viewvc/wtl/?view=tar 2.安装App Wizard 找到"VS安装目录\VC\V ...
- vue 简单原理
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- Generative Adversarial Network - Python实现
算法特征 ①. discriminator区别真假; ②. generator以假乱真 算法推导 Part Ⅰ: 熵之相关定义 entropy之定义如下, \[\begin{equation*} H( ...
- robots.txt 文件说明
robots其实就是指Robots协议,Robots协议(也称为爬虫协议.机器人协议等)的全称是"网络爬虫排除标准"(Robots Exclusion Protocol),网站通过 ...
- CH32V307/CH32V203 IO翻转速度测试
CH32V307/CH32V203 IO极限翻转测试 记录RISC-V MCU CH32V307/CH32V203 在144MHz主频.-Os优化下,IO极限翻转频率. GPIO初始化代码如下: /* ...
- 网页端微信小程序客服
https://mpkf.weixin.qq.com/ 可以设置自动回复
- vue请求插件axios响应拦截302
axios.interceptors.response.use(function (response) { return response;}, function (error) { // 对请求错误 ...
- java中post发送json格式数据
/** * 发送post请求 * @param URL 数据发送地址 * @param json json格式数据内容 * @param headParams 请求头内容 * @return 请求结果 ...
- 渗透测试工具sqlmap基础教程 【转】
转载请注明出处:http://blog.csdn.net/zgyulongfei/article/details/41017493 作者:羽龍飛 本文仅献给想学习渗透测试的sqlmap小白,大牛请绕过 ...
- 查询最上活动的activity
adb shell dumpsys window windows | grep mCurrent