Skip to content

Commit dc9f5ab

Browse files
authored
[20251013] BOJ / G5 / 계란으로 계란치기 / 이준희
1 parent 7e2ec9b commit dc9f5ab

File tree

1 file changed

+60
-0
lines changed

1 file changed

+60
-0
lines changed
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.*;
4+
5+
public class Main {
6+
static int n;
7+
static int[] str, weight;
8+
static int answer = 0;
9+
10+
public static void main(String[] args) throws IOException {
11+
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
12+
n = Integer.parseInt(br.readLine());
13+
str = new int[n];
14+
weight = new int[n];
15+
16+
for (int i = 0; i < n; i++) {
17+
StringTokenizer st = new StringTokenizer(br.readLine());
18+
str[i] = Integer.parseInt(st.nextToken());
19+
weight[i] = Integer.parseInt(st.nextToken());
20+
}
21+
22+
dfs(0);
23+
System.out.println(answer);
24+
}
25+
26+
static void dfs(int idx) {
27+
if (idx == n) {
28+
int broken = 0;
29+
for (int i = 0; i < n; i++) {
30+
if (str[i] <= 0) broken++;
31+
}
32+
answer = Math.max(answer, broken);
33+
return;
34+
}
35+
36+
if (str[idx] <= 0) {
37+
dfs(idx + 1);
38+
return;
39+
}
40+
41+
boolean hit = false;
42+
43+
for (int i = 0; i < n; i++) {
44+
if (i == idx || str[i] <= 0) continue;
45+
46+
hit = true;
47+
48+
str[idx] -= weight[i];
49+
str[i] -= weight[idx];
50+
51+
dfs(idx + 1);
52+
53+
str[idx] += weight[i];
54+
str[i] += weight[idx];
55+
}
56+
57+
if (!hit) dfs(idx + 1);
58+
}
59+
}
60+
```

0 commit comments

Comments
 (0)