HDU-1010 Tempter of the Bone Deep search template problem (DPS) Report

Source: Internet
Author: User

Tempter of the BoneTime limit:2000/1000 MS (java/others) Memory limit:65536/32768 K (java/others)
Total submission (s): 88587 Accepted Submission (s): 24116


Problem DescriptionThe Doggie found a bone in an ancient maze, which fascinated him a lot. However, when he picked it up, the maze began to shake, and the doggie could feel the ground sinking. He realized that the bone is a trap, and he tried desperately to get out of this maze.

The maze is a rectangle with sizes N by M. There is a door in the maze. At the beginning, the door is closed and it would open at the t-th second for a short period of time (less than 1 second) . Therefore the doggie had to arrive in the door on exactly the t-th second. In every second, he could move one block to one of the upper, lower, left and right neighboring blocks. Once He entered a block, the ground of this block would start-to-sink and disappear in the next second. He could not stay on one block for more than one second, nor could he move into a visited block. Can the poor doggie survive? Please help him.

Inputthe input consists of multiple test cases. The first line of all test case contains three integers n, m, and T (1 < N, m < 7; 0 < T <), which denote The sizes of the maze and the time at which the door would open, respectively. The next N lines give the maze layout, with all line containing M characters. A character is one of the following:

' X ': a block of wall, which the doggie cannot enter;
' S ': The start point of the doggie;
' D ': the Door; Or
'. ': an empty block.

The input is terminated with three 0 ' s. This test is a not-to-be processed.

Outputfor each test case, print on one line "YES" if the doggie can survive, or "NO" otherwise.

Sample Input
4 4 5S. X... X... Xd.... 3 4 5S. X... X.... D0 0 0

Sample Output
NOYES

Authorzhang, ZhengTest Instructions:

Give you a maze of n rows M-Columns, x represents the Wall, "." On behalf of the road, s for the starting point, D for the end, ask can just in k seconds from the beginning to reach the end.

Exercises

Template Dfs, no pruning required. Open a two-dimensional array to go up and down, open a oount record steps, if count>k, has not come to the direct break.

Reference code:

#include <cmath> #include <iostream>using namespace Std;char str[10][10];int map[10][10],v[4][2]={0,1,0,-    1,1,0,-1,0};int n,m,k,i,j,flag,ax,ay,bx,by;void dfs (int x,int y,int count) {int mx,my;        if (bx==x&&by==y) {if (k==count) flag=1;    Return    } if (count>=k) return;            if (str[x][y]!= ' x ') {for (int i=0;i<4;i++) {mx=x+v[i][0];            MY=Y+V[I][1]; if (mx>=1&&mx<=n&&my>=1&&my<=m&&!map[mx][my]&&str[mx][my]!=                ' X ') {map[mx][my]=1;                DFS (MX,MY,COUNT+1);                map[mx][my]=0;            if (flag) return; }}}}int Main () {while (scanf ("%d%d%d", &n,&m,&k)!=eof&& (n+m+k)) {memset (ma        P,0,sizeof (map));        int count;            for (i=1;i<=n;i++) {GetChar ();          for (j=1;j<=m;j++)  {scanf ("%c", &str[i][j]);                    if (str[i][j]== ' S ') {ax=i;                Ay=j;                    } if (str[i][j]== ' D ') {bx=i;                By=j;        }}} GetChar (); if (ABS (BX-AX) +abs (by-ay) >k| |        (ax+bx+ay+by+k)%2==1) printf ("no\n");            else {flag=0;            count=0;            Map[ax][ay]=1;            DFS (Ax,ay,count);            if (flag) printf ("yes\n");        else printf ("no\n");  }} return 0;}




Copyright NOTICE: This article for Bo Master original article, casually reproduced.

HDU-1010 Tempter of the Bone Deep search template problem (DPS) Report

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.