HDU 1010
/*************************************** * *********************************> File Name: hdu1010.cpp> author: Yuan> mail:> created time: on Wednesday 22, November 05, 2014 ******************************** **************************************** /# include <iostream> # include <cstdio> # include <cstring> # include <cstdlib> # include <algorithm> # include <cmath> using namespace STD; int n, m, T, start_x, start_y, door_x, door_y; char Map [10] [10]; bool ans; bool flag [10] [10]; int next [4] [2] = {,-, 0, -1}; bool check (INT pos_x, int pos_y) {If (flag [pos_x] [pos_y] = 0 & pos_x> = 0 & pos_x <n & pos_y> = 0 & pos_y <M & (Map [pos_x] [pos_y] = '. '| map [pos_x] [pos_y] = 'D') return 1; return 0;} void DFS (INT cur_x, int cur_y, int count) {// int cur_x = point/m; // int cur_y = point % m; // printf ("cur_x: % d, cur_y: % d \ n", cur_x, cur_y); If (count> T) return; If (ANS = 1) return; If (cur_x = door_x & cur_y = door_y) {If (COUNT = T) ans = 1; // printf ("count: % d \ n ", count); return;} int temp = (t-count)-ABS (door_x-cur_x)-ABS (door_y-cur_y ); if (temp <0 | temp & 1) return; For (INT I = 0; I <4; I ++) {int pos_x = cur_x + next [I] [0]; int pos_y = cur_y + next [I] [1]; If (check (pos_x, pos_y )) {flag [pos_x] [pos_y] = 1; DFS (pos_x, pos_y, Count + 1); flag [pos_x] [pos_y] = 0 ;}} int main () {// printf ("Zhang \ n "); While (~ Scanf ("% d", & N, & M, & T) {// scanf ("% d", & N, & M, & T); If (! N &&! M &&! T) break; memset (MAP, 0, sizeof (MAP); memset (flag, 0, sizeof (FLAG); ans = 0; For (INT I = 0; I <n; I ++) {scanf ("% s", map [I]) ;}// for (INT I = 0; I <n; I ++) // printf ("% s \ n", map [I]); For (INT I = 0; I <n; I ++) for (Int J = 0; j <m; j ++) {If (Map [I] [J] = 's') start_x = I, start_y = J; if (Map [I] [J] = 'D') door_x = I, door_y = J;} // printf ("start_x: % d, start_y: % d, door_x: % d, door_y: % d \ n ", start_x, start_y, door_x, door_y); flag [start_x] [start_y] = 1; // int start_point = start_x * m + start_y; DFS (start_x, start_y, 0); If (ANS) printf ("Yes \ n "); else printf ("NO \ n");} return 0 ;}
HDU 1010 Deep Search + branch reduction