题解 | #迷宫问题#
迷宫问题
https://www.nowcoder.com/practice/cf24906056f4488c9ddb132f317e03bc
def dfs(i, j): if not 0 <= i < m or not 0 <= j < n or matrix[i][j] == 1: return False if i == m-1 and j == n-1: res.append((i, j)) return True matrix[i][j] = 1 res.append((i, j)) if dfs(i+1, j) or dfs(i, j+1) or dfs(i-1, j) or dfs(i, j-1): return True res.pop() while True: try: m, n = list(map(int, input().split())) matrix = [] for _ in range(m): l = list(map(int, input().split())) matrix.append(l) res = [] dfs(0, 0) for i, j in res: print(f'({i},{j})') except: break