递归回溯解迷宫 python3
迷宫问题
http://www.nowcoder.com/questionTerminal/cf24906056f4488c9ddb132f317e03bc
def middle(array,row,column,point,res):
x=point[0]
y=point[1]
res.append((x,y))
if x==row-1 and y==column-1:
return res
if x <row-1 and array[x+1][y]==0:
flag=middle(array,row,column,(x+1,y),res)
if(not flag):
res.pop()
else:
return flag
if y <column-1 and array[x][y+1]==0:
flag=middle(array,row,column,(x,y+1),res)
if(not flag):
res.pop()
else:
return flag
while True:
try:
row, column = map(int, input().strip().split())
array=[]
for i in range(row):
everyRow=list(map(int, input().strip().split()))
array.append(everyRow)
a=[]
a.append((0,0))
res=middle(array,row,column,(0,0),[])
for i in res:
print("({},{})".format(i[0], i[1]) )
except EOFError:
break