Skip to content

Commit 72e4e33

Browse files
authored
[20250608] BOJ / G4 / 호텔 / 이강현
1 parent 821523e commit 72e4e33

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

lkhyun/202506/08 BOJ G4 호텔.md

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
```java
2+
import java.io.*;
3+
import java.util.*;
4+
5+
public class Main {
6+
static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
7+
static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out));
8+
static StringTokenizer st;
9+
static int C,N;
10+
static int[] cost;
11+
static int[] client;
12+
static int[] dp;
13+
14+
public static void main(String[] args) throws IOException {
15+
st = new StringTokenizer(br.readLine());
16+
C = Integer.parseInt(st.nextToken());
17+
N = Integer.parseInt(st.nextToken());
18+
19+
cost = new int[N];
20+
client = new int[N];
21+
dp = new int[1200]; //인덱스만큼의 인원을 홍보할때 그 비용
22+
Arrays.fill(dp,Integer.MAX_VALUE);
23+
dp[0] = 0;
24+
25+
for (int i = 0; i < N; i++) {
26+
st = new StringTokenizer(br.readLine());
27+
cost[i] = Integer.parseInt(st.nextToken()); //홍보 비용
28+
client[i] = Integer.parseInt(st.nextToken()); //홍보했을때 얻는 고객 수
29+
}
30+
31+
for (int i = 0; i < N; i++) {//모든 도시에 대해
32+
for (int j = client[i]; j < dp.length; j++) {
33+
if(dp[j-client[i]] != Integer.MAX_VALUE) {
34+
dp[j] = Math.min(dp[j], dp[j-client[i]] + cost[i]);
35+
}
36+
}
37+
}
38+
int min = Integer.MAX_VALUE;
39+
for (int i = C; i < dp.length ; i++) {
40+
min = Math.min(min, dp[i]);
41+
}
42+
bw.write(min + "");
43+
bw.close();
44+
}
45+
}
46+
47+
```

0 commit comments

Comments
 (0)