You are viewing a single comment's thread. Return to all comments →
to guarantee the lowest path, we need to run every possible combination. How can I optimize it? is gradient descent ok?
import sys n = int(input()) ar = [] ar2 = [] for a in range(n): ar.append([int(x) for x in input().split()]) ar2.append([0 for x in range(5)]) ar2[0][0]=ar[0][0] for i in range(1,n): ar2[0][i]=ar2[0][i-1]+ar[0][i] ar2[i][0]=ar2[i-1][0]+ar[i][0] for i in range(1,n): for j in range(1,n): ar2[i][j]=min(ar2[i][j-1],ar2[i-1][j])+ar[i][j] print(ar2[n-1][n-1])
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #81: Path sum: two ways
You are viewing a single comment's thread. Return to all comments →
to guarantee the lowest path, we need to run every possible combination. How can I optimize it? is gradient descent ok?