Skip to content

Commit f30e668

Browse files
authored
Merge pull request #794 from AlgorithmWithGod/zinnnn37
[20250901] BOJ / G4 / 호텔 / 김민진
2 parents 8cda66b + a21b423 commit f30e668

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed

zinnnn37/202509/1 BOJ G4 호텔.md

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
```java
2+
import java.io.*;
3+
import java.util.Arrays;
4+
import java.util.StringTokenizer;
5+
6+
public class BJ_1106_호텔 {
7+
8+
private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
9+
private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
10+
private static StringTokenizer st;
11+
12+
private static int C;
13+
private static int N;
14+
private static int[] dp;
15+
private static int[][] cost;
16+
17+
public static void main(String[] args) throws IOException {
18+
init();
19+
sol();
20+
}
21+
22+
private static void init() throws IOException {
23+
st = new StringTokenizer(br.readLine());
24+
C = Integer.parseInt(st.nextToken());
25+
N = Integer.parseInt(st.nextToken());
26+
27+
cost = new int[N][2];
28+
for (int i = 0; i < N; i++) {
29+
st = new StringTokenizer(br.readLine());
30+
cost[i][0] = Integer.parseInt(st.nextToken());
31+
cost[i][1] = Integer.parseInt(st.nextToken());
32+
}
33+
34+
dp = new int[C + 100];
35+
Arrays.fill(dp, 987654321);
36+
dp[0] = 0;
37+
}
38+
39+
private static void sol() throws IOException {
40+
for (int[] c : cost) {
41+
for (int i = c[1]; i < C + 100; i++) {
42+
dp[i] = Math.min(dp[i], dp[i - c[1]] + c[0]);
43+
}
44+
}
45+
bw.write(findMin() + "");
46+
bw.flush();
47+
bw.close();
48+
br.close();
49+
}
50+
51+
private static int findMin() {
52+
int ans = dp[C];
53+
for (int i = C + 1; i < C + 100; i++) {
54+
ans = Math.min(ans, dp[i]);
55+
}
56+
return ans;
57+
}
58+
59+
}
60+
```

0 commit comments

Comments
 (0)