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