Skip to content

Commit 5534d0a

Browse files
committed
[BOJ] 14728 벼락치기 (G5)
1 parent 2c4d96d commit 5534d0a

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

최어진/11주차/260312.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# 백준 14728번: 벼락치기
2+
3+
import sys
4+
input = sys.stdin.readline
5+
6+
# N <= 10^2
7+
# T <= 10^4
8+
N, T = map(int, input().rstrip().split())
9+
10+
# costs[i], profits[i]: i번째 단원을 공부했을 때의 비용과 이득
11+
costs = [0]
12+
profits = [0]
13+
for _ in range(N):
14+
cost, profit = map(int, input().rstrip().split())
15+
costs.append(cost)
16+
profits.append(profit)
17+
18+
# dp[i][j]: j초 동안 1 ~ i단원까지 중 얻을 수 있는 최고 점수
19+
dp = [[0 for _ in range(T + 1)] for _ in range(N + 1)]
20+
answer = 0
21+
22+
for i in range(1, N + 1):
23+
for j in range(T + 1):
24+
cost, profit = costs[i], profits[i]
25+
if cost <= j:
26+
dp[i][j] = max(dp[i - 1][j], dp[i - 1][j - cost] + profit)
27+
else:
28+
dp[i][j] = dp[i - 1][j]
29+
30+
print(dp[N][T])

0 commit comments

Comments
 (0)