Skip to content

Commit c9c9e1d

Browse files
authored
Merge pull request #377 from AlgorithmWithGod/suyeun84
[20250621] BOJ / G4 / 호텔 / 김수연
2 parents cc6598a + e4dc9f5 commit c9c9e1d

File tree

1 file changed

+33
-0
lines changed

1 file changed

+33
-0
lines changed
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class boj1106 {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static StringTokenizer st;
8+
static void nextLine() throws Exception {st = new StringTokenizer(br.readLine());}
9+
static int nextInt() {return Integer.parseInt(st.nextToken());}
10+
11+
public static void main(String[] args) throws Exception {
12+
nextLine();
13+
int C = nextInt();
14+
int N = nextInt();
15+
int[] dp = new int[C+100];
16+
int answer = Integer.MAX_VALUE;
17+
Arrays.fill(dp, Integer.MAX_VALUE);
18+
dp[0] = 0;
19+
for (int i = 0; i < N; i++) {
20+
nextLine();
21+
int cost = nextInt();
22+
int num = nextInt();
23+
for (int j = num; j < C+100; j++) {
24+
if (dp[j - num] != Integer.MAX_VALUE) {
25+
dp[j] = Math.min(dp[j], dp[j-num] + cost);
26+
}
27+
}
28+
}
29+
for (int i = C; i < C+100; i++) answer = Math.min(answer, dp[i]);
30+
System.out.println(answer);
31+
}
32+
}
33+
```

0 commit comments

Comments
 (0)