From c4da44f325afc562235a002a07072a5953e831ef Mon Sep 17 00:00:00 2001 From: suyeun84 <81475092+suyeun84@users.noreply.github.com> Date: Mon, 13 Oct 2025 23:37:16 +0900 Subject: [PATCH] =?UTF-8?q?[20251013]=20BOJ=20/=20G5=20/=20=EA=B3=84?= =?UTF-8?q?=EB=9E=80=EC=9C=BC=EB=A1=9C=20=EA=B3=84=EB=9E=80=EC=B9=98?= =?UTF-8?q?=EA=B8=B0=20/=20=EA=B9=80=EC=88=98=EC=97=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...04\353\236\200\354\271\230\352\270\260.md" | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100644 "suyeun84/202510/13 BOJ G5 \352\263\204\353\236\200\354\234\274\353\241\234 \352\263\204\353\236\200\354\271\230\352\270\260.md" diff --git "a/suyeun84/202510/13 BOJ G5 \352\263\204\353\236\200\354\234\274\353\241\234 \352\263\204\353\236\200\354\271\230\352\270\260.md" "b/suyeun84/202510/13 BOJ G5 \352\263\204\353\236\200\354\234\274\353\241\234 \352\263\204\353\236\200\354\271\230\352\270\260.md" new file mode 100644 index 00000000..cbdb21a4 --- /dev/null +++ "b/suyeun84/202510/13 BOJ G5 \352\263\204\353\236\200\354\234\274\353\241\234 \352\263\204\353\236\200\354\271\230\352\270\260.md" @@ -0,0 +1,59 @@ +```java +import java.io.*; +import java.util.*; + +public class boj16987 { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static StringTokenizer st; + static void nextLine() throws Exception { st = new StringTokenizer(br.readLine()); } + static int nextInt() { return Integer.parseInt(st.nextToken()); } + + static int N, answer = 0; + public static void main(String[] args) throws Exception { + nextLine(); + N = nextInt(); + Egg[] eggs = new Egg[N]; + for (int i = 0; i < N; i++) { + nextLine(); + eggs[i] = new Egg(nextInt(), nextInt()); + } + + dfs(0, eggs); + System.out.println(answer); + } + + public static void dfs(int idx, Egg[] eggs) { + if (idx == N) { + int cnt = 0; + for (int i = 0; i < N; i++) { + if (eggs[i].s <= 0) cnt++; + } + answer = Math.max(answer, cnt); + return; + } + if (eggs[idx].s < 0) dfs(idx+1, eggs); + else { + boolean flag = true; + for (int i = 0; i < N; i++) { + if (eggs[i].s <= 0 || idx == i) continue; + flag = false; + eggs[i].s -= eggs[idx].w; + eggs[idx].s -= eggs[i].w; + dfs(idx+1, eggs); + eggs[i].s += eggs[idx].w; + eggs[idx].s += eggs[i].w; + } + if (flag) dfs(idx+1, eggs); + } + } + + static class Egg { + int s, w; + public Egg(int s, int w) { + this.s = s; + this.w = w; + } + } +} + +```