๋ฌธ์
https://school.programmers.co.kr/learn/courses/30/lessons/43105
ํ์ด
# ํ๋ก๊ทธ๋๋จธ์ค 3๋จ๊ณ - ์ ์ ์ผ๊ฐํ
def solution(triangle):
answer = 0
dp = [[0]*i for i in range(1, len(triangle)+1)]
dp[0][0] = triangle[0][0]
dp[1][0] = dp[0][0] + triangle[1][0]
dp[1][1] = dp[0][0] + triangle[1][1]
for i in range(2, len(triangle)):
for j in range(len(triangle[i])):
if j == 0:
dp[i][j] = dp[i-1][j] + triangle[i][j]
elif i == j:
dp[i][j] = dp[i-1][j-1] + triangle[i][j]
else:
dp[i][j] = max(dp[i-1][j-1], dp[i-1][j]) + triangle[i][j]
answer = max(dp[-1])
return answer
print(solution([[7], [3, 8], [8, 1, 0], [2, 7, 4, 4], [4, 5, 2, 6, 5]]))
DP๋ฅผ ์ด์ฉํ ํ์ด
ํญ์ ์ธ๋ฑ์ค ์ชฝ์์ ๋ฌธ์ ๋ฅผ ์ผ์ผ์ผ์ ์๊ฐ์ ๋ญ๋นํ๊ฒ๋๋ค..
์ ํ์ธํ๋๋ก ํ์