Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- N, M = map(int, input().split())
- counts = [[-1] * M for i in range(N)]
- counts[0][0] = 1
- def answer(i, j):
- if counts[i][j] >= 0:
- return counts[i][j]
- counts[i][j] = 0
- if i - 2 >= 0:
- if j - 1 >= 0:
- counts[i][j] += answer(i - 2, j - 1)
- if j + 1 <= M - 1:
- counts[i][j] += answer(i - 2, j + 1)
- if j - 2 >= 0:
- if i - 1 >= 0:
- counts[i][j] += answer(i - 1, j - 2)
- if i + 1 <= N - 1:
- counts[i][j] += answer(i + 1, j - 2)
- return counts[i][j]
- print(answer(N - 1, M - 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement