You are viewing a single comment's thread. Return to all comments →
100 points. Python 3
def max_path(n,triangle): temp=[[] for _ in range(n)] for k in triangle[-1]: temp[-1].append(k) for i in range(n-2,-1,-1): for j in range(i+1): temp[i].append(triangle[i][j]+max(temp[i+1][j],temp[i+1][j+1])) return temp[0][0] t=int(input().strip()) for _ in range(t): n=int(input().strip()) triangle=[] for i in range(n): triangle.append(list(map(int,input().strip().split()))) print(max_path(n,triangle))
Seems like cookies are disabled on this browser, please enable them to open this website
Project Euler #67: Maximum path sum II
You are viewing a single comment's thread. Return to all comments →
100 points. Python 3