You are viewing a single comment's thread. Return to all comments →
M, DP = [], [] for _ in range(int(input())): M.append(list(map(int, input().split()))) DP.append(M[-1][-1]) for i in range(len(M)-2, -1, -1): DP[0] += M[0][i] for j in range(1, len(M)): DP[j] = min(DP[j], DP[j-1]) + M[j][i] for j in range(len(M)-2, -1, -1): DP[j] = min(DP[j], DP[j+1] + M[j][i]) print(min(DP))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #82: Path sum: three ways
You are viewing a single comment's thread. Return to all comments →