반응형
https://www.acmicpc.net/problem/12865
유명한 배낭 문제!!
n, k = map(int, input().split())
items = []
for i in range(n):
w, v = map(int, input().split())
items.append([w, v])
dp = [[0]*(k+1) for _ in range(n+1)]
for i in range(1, n+1):
cw, cv = items[i - 1]
for j in range(1, k+1):
if cw <= j:
dp[i][j] = max(dp[i-1][j], cv + dp[i-1][j-cw])
else:
dp[i][j] = dp[i-1][j]
print(dp[-1][-1])
댓글