Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fin = open("turtle.in")
- fout = open("turtle.out", "w")
- h, w = map(int, fin.readline().split(" "))
- b = [[0] * w for i in range(h)]
- a = [[0] * w for i in range(h)]
- for i in range(h):
- c = fin.readline().split()
- for j in range(w):
- a[i][j] = int(c[j])
- b[h-1][0] = a[h-1][0]
- for i in range(1, w):
- b[h-1][i] = b[h-1][i-1] + a[h-1][i]
- for i in range(1, h):
- b[h-i-1][0] = b[h-i][0] + a[h-i-1][0]
- for i in range(1, h):
- for j in range(1, w):
- b[h-i-1][j] = max(b[h-i][j], b[h-i-1][j-1]) + a[h-i-1][j]
- print(b[0][w-1], file=fout)
- fout.close()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement