HDU 1010 (DFS) The Temptation of Bones

Source: Internet
Author: User

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

Starting from S, ask if you can reach the end point in time t d,x as a barrier

It is important to be aware that it is time to arrive at T, not within t

Deep search, attention to pruning the remaining lattice is more than t time to cut off this very good think, but still will time out, there is a pruning is dependent on

Parity pruning

For example, the map relies on parity;

0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1
1 0 1 0 1 0
0 1 0 1 0 1 You can find even one step to an odd number, odd steps must be to even, so when the location of parity and destination D is not the same time
Be sure to walk an odd number of steps, just take even step, judge this to prune

Code

1#include <stdio.h>2#include <stdlib.h>3 BOOLFlag;4 intN,m,t,i,j,x1,y1,x2,y2,num;5 intdix[]={1,0,0,-1};6 intdiy[]={0,1,-1,0};7 Charstr[8][8];8 voidDFS (intKintLintTC)9 {Ten     inti; One     if(Tc==t && k==x2 &&l==y2) Aflag=true; -     if(flag==true)return; -     if(ABS (X2-K) +abs (y2-l) &GT;T-TC)return ; Two backtracking the     if((ABS (X2-K) +abs (y2-l))%2! = (T-TC)%2)return; -      for(i=0;i<4; i++) -     { -         intdx=k+Dix[i]; +         intdy=l+Diy[i]; -         if(dx>=0&& dx<n && dy>=0&& dy<m && str[dx][dy]!='X') +         { Astr[dx][dy]='X'; atDFS (dx,dy,tc+1); -str[dx][dy]='.'; -         } -     } - } - intMain () in { -      while(SCANF (" %d%d%d",&n,&m,&t)) to     { + GetChar (); -         if(n==0&&m==0&&t==0) the              Break; *num=0; $flag=false;Panax Notoginseng          for(i=0; i<n;i++) -         { the              for(j=0; j<m;j++) +             { Ascanf"%c",&str[i][j]); the                 if(str[i][j]=='S') +                 { -x1=i;y1=J; $                 } $                 Else if(str[i][j]=='D') -                 { -X2=i;y2=J; thenum++; -                 }Wuyi                 Else if(str[i][j]=='.') the                 { -num++; Wu                 } -             } About GetChar (); $         } -str[x1][y1]='X'; -         if(num>=t) -DFS (X1,y1,0); A         if(flag==true) +printf"yes\n"); the         Else -printf"no\n"); $     } the     return 0; the}


HDU 1010 (DFS) The Temptation of Bones

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.