File tree Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Expand file tree Collapse file tree 2 files changed +40
-1
lines changed Original file line number Diff line number Diff line change 134
134
135
135
| 난이도 | 번호 | 제목 | 링크 |
136
136
| ------ | ---- | ---- | ------------------ |
137
- | ![ ?? ] | - | - | < https://boj.kr/- > |
137
+ | ![ S2 ] | 12867 | n차원 여행 | < https://boj.kr/12867 > |
138
138
139
139
<!-- solved.ac 문제 난이도 별 태그 이미지 -->
140
140
Original file line number Diff line number Diff line change
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
+ }
You can’t perform that action at this time.
0 commit comments