Skip to content

Commit 29d0f2a

Browse files
authored
Create 1106.cpp
1 parent df5e78e commit 29d0f2a

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed

2주차 Knapsack/박준석/1106.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
for (int i = 0; i < N; i++) {
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+
for (int j = 0; j < 100001; j++) {
31+
if (dp[j] >= C) {
32+
cout << j;
33+
break;
34+
}
35+
}
36+
37+
}

0 commit comments

Comments
 (0)