Advertisement
Guest User

Untitled

a guest
Apr 4th, 2020
541
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.51 KB | None | 0 0
  1. N, M = map(int, input().split())
  2.  
  3. counts = [[-1] * M for i in range(N)]
  4. counts[0][0] = 1
  5.  
  6. def answer(i, j):
  7.     if counts[i][j] >= 0:
  8.         return counts[i][j]
  9.  
  10.     counts[i][j] = 0   
  11.  
  12.     if i - 2 >= 0:
  13.         if j - 1 >= 0:
  14.             counts[i][j] += answer(i - 2, j - 1)
  15.         if j + 1 <= M - 1:
  16.             counts[i][j] += answer(i - 2, j + 1)
  17.  
  18.     if j - 2 >= 0:
  19.         if i - 1 >= 0:
  20.             counts[i][j] += answer(i - 1, j - 2)
  21.         if i + 1 <= N - 1:
  22.             counts[i][j] += answer(i + 1, j - 2)
  23.  
  24.     return counts[i][j]
  25.  
  26.  
  27. print(answer(N - 1, M - 1))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement