File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
kuyhochung/1. 매주 문제풀이/51주차 Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 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+ }
You can’t perform that action at this time.
0 commit comments