In the by matrix below, the minimal path sum from
the top left to the bottom right, by only moving to the right
and down, is indicated in bold red and is equal to .
Find the minimal path sum, in matrix.txt (right click and
“Save Link/Target As…”), a 31K text file containing a by matrix, from the top left to the
bottom right by only moving right and down.
a = [] ls = open('p081_matrix.txt', 'r').readlines() n = len(ls) f = [[10 ** 10for x inrange(n)] for y inrange(n)] for i inrange(n): b = [int(x) for x in ls[i][:-1].split(',')] a.append(b)
f = [[10 ** 10for x inrange(n + 1)] for y inrange(n + 1)] f[0][1] = 0 for i inrange(1, n + 1): for j inrange(1, n + 1): f[i][j] = min(f[i - 1][j], f[i][j - 1]) + a[i-1][j-1] print(f[n][n])