标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 82702 Accepted Submission(s): 22531
1 #include<stdio.h> 2 #include<string.h> 3 int n , m , T ; 4 bool vis[10][10] , flag; 5 char map[10][10] ; 6 int move[][2] = {{1,0} , {-1,0} , {0,1} , {0,-1}} ; 7 int step = 0; 8 9 void dfs (int sx , int sy , int step ) 10 { 11 if (step == T + 1 && map[sx][sy] == ‘D‘) { 12 flag = 1 ; 13 return ; 14 } 15 // printf ("(%d,%d) %c step=%d\n" , sx , sy , map[sx][sy] , step) ; 16 if (map[sx][sy] == ‘D‘) return ; 17 if (step > T) return ; 18 for (int i = 0 ; i < 4 ; i ++) { 19 int x , y ; 20 x = sx + move[i][0] ; 21 y = sy + move[i][1] ; 22 if (x < 0 || y < 0 || x >= n || y >= m) continue ; 23 if (map[x][y] == ‘X‘) continue ; 24 if (vis[x][y]) continue ; 25 vis[x][y] = 1 ; 26 dfs (x , y , step + 1) ; 27 if (flag) return ; 28 vis[x][y] = 0 ; 29 } 30 } 31 32 int main () 33 { 34 //freopen ("a.txt" , "r" , stdin ) ; 35 while (~ scanf ("%d%d%d" , &n , &m , &T)) { 36 if (n == 0 &&m == 0 && T == 0) break ; 37 for (int i = 0 ; i < n; i ++) scanf ("%s" , map[i]) ; 38 flag = 0 ; 39 step = 0 ; 40 memset (vis , 0 , sizeof(vis)) ; 41 for (int i = 0 ; i < n; i ++) { 42 for (int j = 0 ; j < m ; j ++) { 43 if (map[i][j] == ‘S‘) { 44 vis[i][j] = 1 ; 45 dfs (i , j , 1) ; 46 } 47 } 48 } 49 if (flag) puts ("YES") ; 50 else puts ("NO") ; 51 } 52 return 0 ; 53 }
这道题是要奇偶剪枝的,但我没剪也过了。(虽说压线,23333333333333333)
转载:http://www.2cto.com/kf/201307/229103.html
hdu.1010.Tempter of the Bone(dfs+奇偶剪枝)
标签:
原文地址:http://www.cnblogs.com/get-an-AC-everyday/p/4451392.html