Advertisement
kerillmp2

Untitled

Apr 14th, 2021
116
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.86 KB | None | 0 0
  1. def paths(size, path, cur_x, cur_y):
  2.     ans = 0
  3.     if p[3 * size + cur_x][3 * size + cur_y] != 0:
  4.         return p[3 * size + cur_x][3 * size + cur_y]
  5.     if cur_x == size - 1 and cur_y == -size + 1:
  6.         p[3 * size + cur_x][3 * size + cur_y] = 1
  7.         return 1
  8.     if cur_x + cur_y < 2 * (size - 1) and cur_x != size - 1:
  9.         ans += paths(size, path, cur_x + 1, cur_y + 1)
  10.     if cur_x - cur_y < 2 * (size - 1) and cur_x != size - 1:
  11.         ans += paths(size, path, cur_x + 1, cur_y - 1)
  12.     if cur_x + cur_y > -2 * (size - 1) and cur_x - cur_y < 2 * (size - 1):
  13.         ans += paths(size, path, cur_x, cur_y - 2)
  14.     p[3 * size + cur_x][3 * size + cur_y] = ans
  15.     return ans
  16.  
  17.  
  18. n = int(input())
  19. p = []
  20. for i in range(7 * n):
  21.     row = []
  22.     for j in range(7 * n):
  23.         row.append(0)
  24.     p.append(row)
  25. print(paths(n, p, -n + 1, n - 1))
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement