Skip to content

Commit 816a1e5

Browse files
committed
feat: 1106풀이, 문제추천
1 parent aaeba4c commit 816a1e5

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

2주차 Knapsack/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ $$
134134

135135
| 난이도 | 번호 | 제목 | 링크 |
136136
| ------ | ---- | ---- | ------------------ |
137-
| ![??] | - | - | <https://boj.kr/-> |
137+
| ![S2] | 12867 | n차원 여행 | <https://boj.kr/12867> |
138138

139139
<!-- solved.ac 문제 난이도 별 태그 이미지 -->
140140

2주차 Knapsack/양효인/1106.cpp

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
#include <iostream>
2+
using namespace std;
3+
4+
int c, n;
5+
int input[20][2];
6+
int dp[100001];
7+
8+
int countDP(int customer, int cityNum) {
9+
int min = 100 * 1000;
10+
int cost;
11+
if (customer <= 0) return 0;
12+
else if (dp[customer] > 0) return dp[customer];
13+
else {
14+
for (int i = 0; i < cityNum; i++) {
15+
cost = countDP(customer - input[i][1], cityNum) + input[i][0];
16+
min = cost < min ? cost : min;
17+
}
18+
dp[customer] = min;
19+
return min;
20+
}
21+
}
22+
23+
int main() {
24+
ios::sync_with_stdio(false);
25+
cin.tie(0); cout.tie(0);
26+
27+
cin >> c >> n;
28+
for (int i = 0; i < n; i++) {
29+
int a, b;
30+
cin >> a >> b;
31+
input[i][0] = a;
32+
input[i][1] = b;
33+
}
34+
35+
cout << countDP(c, n);
36+
37+
return 0;
38+
39+
}

0 commit comments

Comments
 (0)