有两点需要注意,第一点就是,题意是指在第T秒时门才打开,并不是越早到门口就能越早出去,而是只要存在指定长的路径即可以出去。
第二点,每次深搜发现答案不符都必须将点重新初始化。
#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')))
            {
                    d[nx][ny]=d[i][j]+1;
                    if(dfs(nx,ny))
                    {
                        d[nx][ny]=INF;
                        return true;
                    }
                    else
                        d[nx][ny]=INF;
            }
        }
        d[i][j]=INF;
        return false;
    }
}
 
 
 
 
 
 
 

HDOJ--1010题C++的更多相关文章

  1. HDOJ.1010 Tempter of the Bone (DFS)

    Tempter of the Bone [从零开始DFS(1)] 从零开始DFS HDOJ.1342 Lotto [从零开始DFS(0)] - DFS思想与框架/双重DFS HDOJ.1010 Tem ...

  2. HDU 4768 Flyer (2013长春网络赛1010题,二分)

    Flyer Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submi ...

  3. HDU 4664 Triangulation(2013多校6 1010题,博弈)

    Triangulation Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Tot ...

  4. HDOJ 1004题 Let the Balloon Rise strcmp()函数

    Problem Description Contest time again! How excited it is to see balloons floating around. But to te ...

  5. HDOJ 1312题Red and Black

    Red and Black Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total ...

  6. HDOJ 1013题Digital Roots 大数,9余数定理

    Problem Description The digital root of a positive integer is found by summing the digits of the int ...

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

  8. HDU 4747 Mex (2013杭州网络赛1010题,线段树)

    Mex Time Limit: 15000/5000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submis ...

  9. HDU 4705 Y (2013多校10,1010题,简单树形DP)

    Y Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others)Total Submiss ...

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

随机推荐

  1. Docker 安装 PHP+Nginx

    安装Nginx docker pull nginx 安装PHP docker pull php:7.3.5-fpm 启动PHP-FPM docker run --name myphpfpm -v /d ...

  2. LENGTH,LENGTHB

    LENGTH 1.语法 length(string) 2.说明: 统计字段的字符长度 3.示例: select length('abcd') from dual; --返回值:4 select len ...

  3. Linux内核红黑树1—Documentation/rbtree.txt翻译

    转自:https://www.cnblogs.com/hellokitty2/p/15362630.html 1. 什么是红黑树,它们有什么用?---------------------------- ...

  4. vue webpack打包之后 重新修改配置文件接口API路径,无需修改代码后再打包

    用vue-cli构建的项目通常是采用前后端分离的开发模式,也就是前端与后台完全分离,此时就需要将后台接口地址打包进项目中,但是有的时候需要修改接口地址,为了避免为了修改接口地址而进行修改代码后再重新打 ...

  5. 解决Delphi报Range check error错误

    没有深入研究,大体是Debug下编译的运行就报错,Release下编译的正常. 后来发现Debug模式下会打开越界检查. Project--> Option -->Delphi Compl ...

  6. 初次使用gitee的笔记

    步骤及问题 1.git config --global user.name "username" 2.git config --global user.email "us ...

  7. [转]cfs 调度

    https://www.cnblogs.com/LoyenWang/p/12495319.html 背景 Read the fucking source code! --By 鲁迅 A picture ...

  8. DevExpress控件显示弹出注册对话框的应对方法

    删除Properties下的license.licx,目前来看是可以的 已测试,可以不显示注册对话框

  9. UML各种图实践题

    1. 用状态图描述一部电梯的运行

  10. 回溯-1-N皇后(Backtracking-1-N Queens)

    #include <stdio.h> #define N 4 enum bool {TRUE, FALSE}; void print_Q(int *Q) { int i; for (i = ...