关于深度优先走迷宫的问题
[local]1[/local]我想写一个深度优先走迷宫的代码
但是不知道问题出在哪
麻烦各位帮帮忙
next=[[0,1],[1,0],[0,-1],[-1,0]] m=3 n=3 book=[range(0,4),range(0,4)] for i in range(0,4): for j in range(0,4): book[i][j]=0 map=[[0,0,0,0],[0,0,0,0],[0,0,0,0],[0,0,0,1]] def dfs(x,y,step): if(x==m,y==n): if(step<min): min=step for k in range(0,4): tx=x+next[k][0] ty=y+next[k][1] if(tx>=0&ty>=0&tx<4&ty<4): if(map[tx][ty]!=1&book[tx][ty]==0): book[tx][ty]=1 dfs(tx,ty,step+1) book[tx][ty]=0 dfs(0,0,1)
book=[[0 for i in range(4)] for j in range(4)]
def dfs(x,y,step): global min if x==m and y==n and step<min : min=step