Advertisement
makut

Untitled

Sep 21st, 2014
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.86 KB | None | 0 0
  1. N, M = map(int, input().split())
  2. plan = [None] * (N + 1)
  3. a = [[None] * M for t in range(N)]
  4. for l in range(N):
  5. plan[l] = list(map(int, input().split()))
  6.  
  7. for k in range(N):
  8. if plan[k][1] != 0 and a[k - 1][1] != 0:
  9. a[k][1] = 1
  10. else: a[k][1] = 0
  11. for t in range(M):
  12. if plan[1][t] != 0 and a[1][t - 1] != 0:
  13. a[1][t] = 1
  14. else: a[1][t] = 0
  15.  
  16. for i in range(2, N):
  17. for j in range(2, M):
  18. if plan[i][j - 1] != 0 and plan[i - 1][j] != 0:
  19. a[i][j] = a[i][j - 1] + a[i - 1][j]
  20. elif plan[i][j - 1] == 0 and plan[i -1][j] != 0:
  21. a[i][j] = a[i - 1][j]
  22. elif plan[i][j - 1] != 0 and plan[i -1][j] == 0:
  23. a[i][j] = a[i][j - 1]
  24. elif plan[i][j - 1] == 0 and plan[i -1][j] == 0:
  25. a[i][j] = 0
  26. if a[N - 1][M - 1] != 0:
  27. print(a[N - 1][M - 1])
  28. else: print('Impossible')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement