defdfs(x, y):global ans
if x ==0or x == n or y ==0or y == n:
ans +=1returnfor i inrange(4):
tx = x + directions[i][0]
ty = y + directions[i][1]if arr_map[tx][ty]==0:
arr_map[tx][ty]=1
arr_map[n - tx][n - ty]=1
dfs(tx, ty)
arr_map[tx][ty]=0
arr_map[n - tx][n - ty]=0return ans /4
n =6
ans =0
arr_map =[[0]*(n +1)for i inrange(10)]
directions =[(-1,0),(1,0),(0,-1),(0,1)]
arr_map[3][3]=1# print(arr_map)if __name__ =='__main__':print(dfs(n //2, n //2))# 509# print(ans)"""
注释:
从中心带你(3,3)开始出发,两边对称走,最后总数要除以4
"""
方格分隔(dfs)def dfs(x, y): global ans if x == 0 or x == n or y == 0 or y == n: ans += 1 return for i in range(4): tx = x + directions[i][0] ty = y + directions[i][1] if arr_map[tx][ty] == 0: a