# Tempter of the Bone---hdu1010 (dfs+ pruning)

Source: Internet
Author: User

http://acm.hdu.edu.cn/showproblem.php?pid=1010

Tortured me all afternoon

The main topic: from S point to D Point can just walk K step at the beginning thought is wide search, actually is deep search.

DFS multi-optimization before it's over.

`#include <stdio.h>#include<stdlib.h>#include<algorithm>#include<math.h>#include<string.h>#include<iostream>#include<queue>#include<ctype.h>using namespacestd;#defineN 10#defineMemset (A, B) memset (A,b,sizeof (a))#defineLson r<<1|1#defineRson r<<1structnode{intX,y,step;} S,e;intn,m,k;intdis[4][2]={{1,0},{-1,0},{0,1},{0,-1}};intVis[n][n];CharMaps[n][n];int  is=0;voidDFS (node T) {if( is)        return; if(t.x==e.x && t.y==e.y && t.step==k) { is=true; return; }    if(t.step>=k)return; intMin= (int) (ABS (t.x-e.x) +abs (t.y-e.y)); if(min>k-t.step)return; if(min%2! = (k-t.step)%2)        return; if(T.x==e.x && t.y==e.y)return;    Node q;  for(intI=0;i<4; i++) {q.x=t.x+dis[i][0]; Q.y=t.y+dis[i][1]; Q.step=t.step+1; if( is|| q.x<0|| Q.x>=n | | q.y<0|| Q.y>=m | | maps[q.x][q.y]=='X')            Continue; if(q.x==e.x && q.y==e.y && q.step==k) { is=true; return; }        CharCh=MAPS[Q.X][Q.Y]; MAPS[Q.X][Q.Y]='X';        DFS (q); MAPS[Q.X][Q.Y]=ch; }}intMain () { while(SCANF (" %d%d%d", &n,&m,&k), n+m+k) {memset (maps,0); intans=0;  for(intI=0; i<n;i++) {scanf ("%s", Maps[i]);  for(intj=0; j<m;j++)            {                if(maps[i][j]=='S') {s.x=i; S.y=J; S.step=0; }                Else if(maps[i][j]=='D') {e.x=i; E.y=J; }                Elseans++; }        }        if(K-1>ans) {printf ("no\n"); Continue; } Maps[s.x][s.y]='X';  is=0;        DFS (s); if( is==true) printf ("yes\n"); Elseprintf ("no\n"); }    return 0;}`

Tempter of the Bone---hdu1010 (dfs+ pruning)

Related Keywords:

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.