题解 | #迷宫问题#
迷宫问题
https://www.nowcoder.com/practice/cf24906056f4488c9ddb132f317e03bc
def fun(i, j, ls, tup): if i==m-1 and j==n-1: for x in ls: print("(%s,%s)"%(x[0],x[1])) return if (i, j - 1) != tup and j - 1 >= 0 and dp[i][j - 1] == "0": l = ls[:] l.append((i, j - 1)) fun(i, j - 1, l, (i, j)) if (i, j + 1) != tup and j + 1 <= n - 1 and dp[i][j + 1] == "0": l = ls[:] l.append((i, j + 1)) fun(i, j + 1, l, (i, j)) if (i - 1, j) != tup and i - 1 >= 0 and dp[i - 1][j] == "0": l = ls[:] l.append((i - 1, j)) fun(i - 1, j, l, (i, j)) if (i + 1, j) != tup and i + 1 <= m-1 and dp[i + 1][j] == "0": l = ls[:] l.append((i + 1, j)) fun(i + 1, j, l, (i, j)) l = input().split() m, n = int(l[0]), int(l[1]) dp = [input().split() for _ in range(m)] fun(0,0,[(0,0)],(0,0))