I have done this before ~~ But I don't know how to keep Wa. I made it again today ~~ Always wa ~~ I found that only the input process was forgotten ~~ R c ~~
# Include <iostream> # include <cstring> # include <cstdio> using namespace STD; int n, m; int map [50] [50]; int vis [50] [50]; int XX [4] = {, 0,-1}; int YY [4] = {,-}; int sum; int res [10000]; int judge (int nx, int NY) {If (nx> = n | NX <0 | ny <0 | ny> = m) return 0; else return 1;} int DFS (int x, int y, int cur, int K) {If (cur = 0) return 1; int I; for (I = 0; I <4; I ++) {int Nx = x + XX [I]; int ny = Y + YY [I]; If (! Judge (NX, NY) continue; If (Map [NX] [NY]! = 0) continue; int flag = 0; while (Map [NX] [NY] = 0) {Nx = NX + XX [I]; NY = ny + YY [I]; If (! Judge (NX, NY) {flag = 1; break ;}} if (FLAG) continue; If (! Judge (nx + XX [I], NY + YY [I]) {If (Map [NX] [NY]> 1) {continue ;} else {res [k] = I; Map [NX] [NY] = 0; If (DFS (NX, NY, cur-1, k + 1) return 1; map [NX] [NY] = 1 ;}} else {int T1 = map [NX] [NY]; int t2 = map [NX + XX [I] [NY + YY [I]; Map [NX] [NY] = 0; map [NX + XX [I] [NY + YY [I] = t1 + t2-1; Res [k] = I; If (DFS (NX, NY, cur-1, k + 1) return 1; Map [NX] [NY] = T1; map [NX + XX [I] [NY + YY [I] = t2 ;}} return 0 ;}int main () {While (scanf ("% d", & M, & N )! = EOF) {int I, j; char temp [50] [50]; sum = 0; for (I = 0; I <n; I ++) {scanf ("% s", temp [I]); For (j = 0; j <m; j ++) {If (temp [I] [J] = '. ') map [I] [J] = 0; else {map [I] [J] = temp [I] [J]-'A' + 1; sum + = map [I] [J] ;}} memset (Res,-1, sizeof (RES); int flag = 0; for (I = 0; I <n; I ++) {for (j = 0; j <m; j ++) {If (Map [I] [J] = 0) {If (DFS (I, j, sum, 0) {flag = 1; break ;}} if (FLAG) break ;} printf ("% d \ n", I, j); for (I = 0; Res [I]! =-1; I ++) {If (RES [I] = 0) printf ("R"); else if (RES [I] = 1) printf ("D"); else if (RES [I] = 2) printf ("L"); else printf ("U ");} printf ("\ n");} return 0 ;}