Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def paths(size, path, cur_x, cur_y):
- ans = 0
- if p[3 * size + cur_x][3 * size + cur_y] != 0:
- return p[3 * size + cur_x][3 * size + cur_y]
- if cur_x == size - 1 and cur_y == -size + 1:
- p[3 * size + cur_x][3 * size + cur_y] = 1
- return 1
- if cur_x + cur_y < 2 * (size - 1) and cur_x != size - 1:
- ans += paths(size, path, cur_x + 1, cur_y + 1)
- if cur_x - cur_y < 2 * (size - 1) and cur_x != size - 1:
- ans += paths(size, path, cur_x + 1, cur_y - 1)
- if cur_x + cur_y > -2 * (size - 1) and cur_x - cur_y < 2 * (size - 1):
- ans += paths(size, path, cur_x, cur_y - 2)
- p[3 * size + cur_x][3 * size + cur_y] = ans
- return ans
- n = int(input())
- p = []
- for i in range(7 * n):
- row = []
- for j in range(7 * n):
- row.append(0)
- p.append(row)
- print(paths(n, p, -n + 1, n - 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement