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 ...
随机推荐
- js 俄罗斯方块 canvas
俄罗斯方块背景- canvans 第一次写不知道说些什么好,直接上代码了@_@... jquery引入 <script src="https://cdn.bootcdn.net/aja ...
- java8线程池创建并使用
1.创建@Configurationpublic class ThreadPoolConfig { /** * 创建线程池 */ @Bean(name = "threadPool" ...
- vue3 门户网站搭建3-pinia
引入 pinia 来方便处理全局变量. npm install pinia 1.创建 pinia 2.main 中引入(我这里是直接写的 index,所以导出的是 stores) 3.定义变量 使用: ...
- C# load and unload dll
1. Invoker Any c# project Create a new application domain Create a proxy within the domain Unload th ...
- VMware Workstation 未能启动VMware Authentication Service
(1)今天像往常一样打开vmware启动虚拟机,但是弹出个框,显示VMware Workstations 未启动VMware Authorization Service,让我尝试手动启动. (2)Wi ...
- 51电子-STC89C51开发板:程序烧录(刷写) 到 IC 设置
全部内容,请点击: 51电子-STC89C51开发板:<目录> --------------------------- 正文开始 --------------------------- ...
- 基于ipset的dns代理
###基于源IP的dns白名单 sleep 60s/etc/init.d/firewall restart ###创建ipset集合 命名为src_dns_whitelist#清空原有命名为src_d ...
- sql使用!=查询时会忽略null数据
table_a有3条数据 column1值分别为1,0,null 那么 select * from table_a where column1!='1' 只会查到clumn1为0的数据,null的数据 ...
- sqlalchemy 数据类型
- HDLbits——Lfsr5
Build this LFSR. The reset should reset the LFSR to 1 module top_module( input clk, input reset, // ...