11052-s1 성공

This commit is contained in:
sm4640
2026-03-30 17:41:13 +09:00
parent ae7df30365
commit 8e68290fe3

View File

@@ -0,0 +1,33 @@
# 카드 구매하기
import sys
input = sys.stdin.readline
def solution():
n = int(input().rstrip())
lst = [0] + list(map(int, input().rstrip().split()))
dp = lst[:]
dp[1] = lst[1]
for i in range(2, n+1):
for j in range(i-1, 0, -1):
dp[i] = max(dp[i], dp[j]+lst[i-j])
print(dp[n])
return
solution()
"""
걸린 시간: 35분
시간 복잡도: O(n^2)이다.
해설: dp[i]는 카드 i개를 모으고자 할때, 최대값이라고 하자.
i개를 모으기 위해 i개보다 작은 수들에서 i로 올 수 있는 모든 경우의 수를 보고 최대값을 선택한다.
"""