Skip to content

Commit e74f45e

Browse files
committed
100번 최대 점수 구하기(냅색 알고리즘) 수강 완료
1 parent b71ddd4 commit e74f45e

1 file changed

Lines changed: 29 additions & 1 deletion

File tree

인프런_알고리즘_강의/김태원/섹션 5. Dynamic programming(동적계획법)/100. 최대점수 구하기(냅색 알고리즘).md

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,36 @@
2222
### 출력 예제
2323
41
2424

25-
2625
### 모범 답안
2726
``` Cpp
27+
#include <iostream>
28+
#include <fstream>
29+
#include <vector>
30+
#include <algorithm>
31+
using namespace std;
32+
int main() {
33+
ios_base::sync_with_stdio(false);
34+
ifstream cin;
35+
cin.open("input.txt");
36+
// ps: 풀이 점수
37+
// pt: 풀이 시간
38+
int n = 0, m = 0, ps = 0, pt = 0;
39+
cin >> n >> m;
40+
vector<int> dy(m + 1);
41+
for (int i = 0; i < n; i++) {
42+
cin >> ps >> pt;
43+
// j: 현재 주어진 시간
44+
for (int j = m; j >= pt; j--) {
45+
// 현재 주어진 시간에 얻을 수 있는 최대 점수
46+
// vs
47+
// 다음 문제를 풀었을 때 얻을 수 있는 최대 점수를 합친 값
48+
dy[j] = max(dy[j], dy[j - pt] + ps);
49+
}
50+
}
51+
cout << dy[m];
52+
return 0;
53+
}
54+
// dy[j]의 의미
55+
// j만큼의 시간이 주어졌을 때 얻을 수 있는 최대 점수
2856

2957
```

0 commit comments

Comments
 (0)