forked from ndb796/python-for-coding-test
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy path2.py
More file actions
23 lines (20 loc) · 657 Bytes
/
2.py
File metadata and controls
23 lines (20 loc) · 657 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
n = int(input())
dp = [] # 다이나믹 프로그래밍을 위한 DP 테이블 초기화
for _ in range(n):
dp.append(list(map(int, input().split())))
# 다이나믹 프로그래밍으로 2번째 줄부터 내려가면서 확인
for i in range(1, n):
for j in range(i + 1):
# 왼쪽 위에서 내려오는 경우
if j == 0:
up_left = 0
else:
up_left = dp[i - 1][j - 1]
# 바로 위에서 내려오는 경우
if j == i:
up = 0
else:
up = dp[i - 1][j]
# 최대 합을 저장
dp[i][j] = dp[i][j] + max(up_left, up)
print(max(dp[n - 1]))