题目:
全部代码:
def get_dir(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[tx][ty] == 0: arr[tx][ty] = 1 arr[n - tx][n - ty] = 1 get_dir(tx, ty) arr[tx][ty] = 0 arr[n - tx][n - ty] = 0 return (ans / 4)n = 6ans = 0arr = [[0] * (n + 1) for i in range(10)]directions = [(-1, 0), (1, 0), (0, -1), (0, 1)]arr[3][3] = 1print(get_dir(n // 2, n // 2)) >>> 509.0