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]))