递归回溯解迷宫 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

全部评论

相关推荐

不愿透露姓名的神秘牛友
昨天 10:39
一个证都没&nbsp;我能填什么
凉风落木楚山秋:空白不是说你没证吧,有实践也行
点赞 评论 收藏
分享
程序员小白条:你是沟通了900个,不是投了900份简历,你能投900份,意味着对面都要回复你900次,你早就找到实习了,没亮点就是这样的,别局限地区,时间投的也要早,现在都要7月了
点赞 评论 收藏
分享
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务