P1605 迷宫 - 洛谷 | 计算机科学教育新生态 (luogu.com.cn)https://www.luogu.com.cn/problem/P1605
n, m, t = map(int, input().split())
sx, sy, fx, fy = map(int, input().split())
sx -= 1
sy -= 1
fx -= 1
fy -= 1
ans = 0
dir = [[1, -1, 0, 0], [0, 0, 1, -1]]
mp = []
vis = []
def dfs(x, y):
global ans, n, m, fx, fy
if x == fx and y == fy:
ans += 1
return
if x < 0 or x >= n or y < 0 or y >= m or vis[x][y] == 1:
return
vis[x][y] = 1
for i in range(4):
dx = dir[0][i]
dy = dir[1][i]
tx = dx + x
ty = dy + y
if tx >= 0 and tx < n and ty >= 0 and ty < m and vis[tx][ty] == 0 and mp[tx][ty] == 0:
dfs(tx, ty)
vis[tx][ty] = 0
for i in range(n):
mp.append([])
vis.append([])
for j in range(m):
mp[i].append(0)
vis[i].append(0)
for i in range(t):
xx, yy = map(int, input().split())
mp[xx-1][yy-1] = 1
dfs(sx, sy)
print(ans)
#print(mp)
|