70分,不知道为啥,求大佬检查。。。
  • 板块P1605 迷宫
  • 楼主Cui_qust
  • 当前回复0
  • 已保存回复0
  • 发布时间2024/3/11 17:22
  • 上次更新2024/3/11 19:43:10
查看原帖
70分,不知道为啥,求大佬检查。。。
1259509
Cui_qust楼主2024/3/11 17:22

#迷宫的长、宽、障碍总数 n,m,t=map(int,input().strip().split()) #起点坐标和终点坐标 x1,y1,x2,y2=map(int,input().strip().split())

#定义地图 a=[[0]*20 for i in range(20)]

#障碍点的坐标 z=[[0]*(t+1) for i in range(t+1)] for i in range(1,t+1): z[i][0],z[i][1]=map(int,input().split()) a[z[i][0]][z[i][1]]=-1 #print(z) #print(a) #把障碍物对应的点赋值为-1

#访问数组记录是否走过,0表示没走过,1表示走过 vis=[[0]*20 for i in range(20)] ans=0 def dfs(x,y): global ans if x==x2 and y==y2: #到终点了 ans+=1 #print(ans) return if x<1 or x>n : #出界了 return if y<1 or y>m: return

if a[x][y+1]!=-1 and vis[x][y+1]==0:
    vis[x][y+1]=1
    dfs(x,y+1)
    vis[x][y+1]=0

if a[x+1][y]!=-1 and vis[x+1][y]==0:
    vis[x+1][y]=1
    dfs(x+1,y)
    vis[x+1][y]=0

if a[x-1][y]!=-1 and vis[x-1][y]==0:
    vis[x-1][y]=1
    dfs(x-1,y)
    vis[x-1][y]=0

if a[x][y-1]!=-1 and vis[x][y-1]==0:
    vis[x][y-1]=1
    dfs(x,y-1)
    vis[x][y-1]=0

dfs(x1,y1) print(ans)

2024/3/11 17:22
加载中...