We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent df5e78e commit 29d0f2aCopy full SHA for 29d0f2a
2주차 Knapsack/박준석/1106.cpp
@@ -0,0 +1,37 @@
1
+#include <iostream>
2
+#include <algorithm>
3
+
4
+using namespace std;
5
6
+int main() {
7
+ ios::sync_with_stdio(false);
8
+ cin.tie(NULL);
9
+ cout.tie(NULL);
10
11
+ int C, N;
12
+ cin >> C >> N;
13
14
+ int dp[100001] = { 0, };
15
16
+ int cost[20] = { 0, };
17
+ int cust[20] = { 0, };
18
+ for (int i = 0; i < N; i++) {
19
+ cin >> cost[i] >> cust[i];
20
+ }
21
+ //input
22
23
24
+ for (int j = 0; j < 100001; j++) {
25
+ if (j - cost[i] >= 0) //i번째 값을 빼도 0보다 같거나 크다면
26
+ dp[j] = max(dp[j], dp[j - cost[i]] + cust[i]); // 0/1 중 큰것을 선택
27
28
29
30
31
+ if (dp[j] >= C) {
32
+ cout << j;
33
+ break;
34
35
36
37
+}
0 commit comments