Skip to content

Commit

Permalink
feat : 벼락치기 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
jeeminimini committed Nov 11, 2023
1 parent 7ca7256 commit e3b5e51
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/kotlin/jimin/49week/벼락치기.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
'''
배낭문제
'''

import sys
n, t = map(int, sys.stdin.readline().split())
subjects = [[]]

for i in range(n):
k, s = map(int, sys.stdin.readline().split())
subjects.append([k, s])

dp = [[0 for _ in range(n + 1)] for _ in range(t + 1)]

for i in range(1, n + 1):
for j in range(1, t + 1):
if subjects[i][0] > j:
dp[j][i] = dp[j][i - 1]
else:
dp[j][i] = max(dp[j][i - 1], subjects[i][1] + dp[j - subjects[i][0]][i - 1])

print(dp[-1][-1])

0 comments on commit e3b5e51

Please sign in to comment.