![](zzz/editor/img/code.gif)
程序代码:
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)