题解 | #迷宫问题#
迷宫问题
https://www.nowcoder.com/practice/cf24906056f4488c9ddb132f317e03bc
import sys def dfs(x,y): if x == m-1 and y == n-1: for p in route: print('('+str(p[0])+','+str(p[1])+')') d = [(0,1),(0,-1),(1,0),(-1,0)] for dx, dy in d: newx, newy = dx+x, dy+y if 0<=newx<m and 0<=newy<n and map1[newx][newy] == 0: map1[newx][newy] = 1 route.append((newx,newy)) dfs(newx,newy) map1[newx][newy] = 0 route.pop() return while 1: try: m,n = list(map(int, input().split(' '))) map1 = [] for i in range(m): t = list(map(int, input().split(' '))) map1.append(t) # print(map1) route = [(0,0)] map1[0][0] = 1 dfs(0,0) except: break