-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path43105.py
More file actions
23 lines (18 loc) · 764 Bytes
/
43105.py
File metadata and controls
23 lines (18 loc) · 764 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
# https://programmers.co.kr/learn/courses/30/lessons/43105?language=python3
import copy
def solution(triangle):
length = len(triangle)
sum_dp = copy.deepcopy(triangle)
sum_dp[0] = triangle[0]
for index in range(length-1):
next_value = triangle[index + 1]
for i, v in enumerate(sum_dp[index]):
for add in range(2):
current_idx = i + add
if current_idx > len(next_value):
continue
sum_value = v + next_value[current_idx]
if sum_dp[index+1][current_idx] < sum_value:
sum_dp[index+1][current_idx] = sum_value
return max(sum_dp[length-1])
print(solution([[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]] ))