Advertisement
Guest User

Untitled

a guest
Nov 25th, 2015
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.55 KB | None | 0 0
  1. N, M = map(int, input().split())
  2. array_first = [list(map(int, input().split())) for i in range(N)]
  3. array_second= [[0 for i in range(M)] for j in range(N)]
  4. array_second[0][0] = array_first[0][0]
  5. for i in range(1, M):
  6. array_second[0][i] = array_second[0][i - 1] + array_first[0][i]
  7. for i in range(1, N):
  8. array_second[i][0] = array_second[i - 1][0] + array_first[i][0]
  9. for i in range(1, N):
  10. for j in range(1, M):
  11. array_second[i][j] = array_first[i][j] + min(array_second[i - 1][j], array_second[i][j - 1])
  12. print(array_second[N - 1][M - 1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement