From 8e68290fe30f923e9959a380117f29cd0174d7b1 Mon Sep 17 00:00:00 2001 From: sm4640 Date: Mon, 30 Mar 2026 17:41:13 +0900 Subject: [PATCH] =?UTF-8?q?11052-s1=20=EC=84=B1=EA=B3=B5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- workbook_7319/silver/11052-s1.py | 33 ++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 workbook_7319/silver/11052-s1.py diff --git a/workbook_7319/silver/11052-s1.py b/workbook_7319/silver/11052-s1.py new file mode 100644 index 0000000..6db710b --- /dev/null +++ b/workbook_7319/silver/11052-s1.py @@ -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로 올 수 있는 모든 경우의 수를 보고 최대값을 선택한다. +""" \ No newline at end of file