Skip to content

Commit 49c3346

Browse files
authored
Create Assignment_BOJ_17845_수강과목.py
1 parent e213477 commit 49c3346

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
'''
2+
BOJ #17845. 수강과목 (골드5)
3+
https://www.acmicpc.net/problem/17845
4+
유형: DP, 배낭문제
5+
'''
6+
import sys
7+
input = sys.stdin.readline
8+
9+
n, k = list(map(int, input().rstrip().split())) # n은 최대 공부 시간, k는 과목 수
10+
info = [0] + [list(map(int, input().rstrip().split())) for _ in range(k)]
11+
dp = [[0] * (n + 1) for _ in range(k + 1)]
12+
13+
for i in range(1, k + 1): # i는 현재 고른 과목 수
14+
for j in range(1, n + 1): # j는 최대 시간
15+
if j < info[i][1]: # 시간이 넘친다면
16+
dp[i][j] = dp[i - 1][j] # 해당 과목은 제외
17+
else: # 시간이 넘치지 않는다면
18+
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - info[i][1]] + info[i][0]) # 해당 과목 제외한거 vs 해당 과목 중요도 + (해당 과목 제외) 해당 과목의 시간을 뺀 중요도
19+
20+
print(dp[k][n])

0 commit comments

Comments
 (0)