Skip to content

Commit c25718b

Browse files
committed
벼락치기
1 parent eda69b9 commit c25718b

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
#include <vector>
4+
using namespace std;
5+
6+
#define MAX_N 101
7+
#define MAX_T 10001
8+
9+
int N, T;
10+
vector<pair<int, int> > subjects;
11+
int dp[MAX_N][MAX_T] = {0, };
12+
13+
int main() {
14+
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
15+
16+
//주어진 입력을 받는다.
17+
cin >> N >> T;
18+
for (int i = 0; i < N; i++) {
19+
int k, s;
20+
cin >> k >> s;
21+
subjects.push_back({k, s});
22+
}
23+
24+
for (int i = 1; i <= N; i++) {
25+
int study_time = subjects[i-1].first, credit = subjects[i-1].second;
26+
for (int j = 0; j <= T; j++) {
27+
if (j < study_time) {
28+
dp[i][j] = dp[i-1][j];
29+
}
30+
else {
31+
dp[i][j] = max(dp[i-1][j], dp[i-1][j-study_time] + credit);
32+
}
33+
}
34+
}
35+
36+
cout << dp[N][T];
37+
return 0;
38+
}

0 commit comments

Comments
 (0)