From 8bcc55f06e4a68678eac55dad601c1ece1991dac Mon Sep 17 00:00:00 2001 From: Jonghwan Lee <123362165+0224LJH@users.noreply.github.com> Date: Mon, 24 Nov 2025 10:41:12 +0900 Subject: [PATCH] =?UTF-8?q?[20251124]=20BOJ=20/=20G2=20/=20=EB=A7=88?= =?UTF-8?q?=ED=94=BC=EC=95=84=20/=20=EC=9D=B4=EC=A2=85=ED=99=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...J \353\247\210\355\224\274\354\225\204.md" | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 "0224LJH/202511/24 BOJ \353\247\210\355\224\274\354\225\204.md" diff --git "a/0224LJH/202511/24 BOJ \353\247\210\355\224\274\354\225\204.md" "b/0224LJH/202511/24 BOJ \353\247\210\355\224\274\354\225\204.md" new file mode 100644 index 00000000..2d0c6568 --- /dev/null +++ "b/0224LJH/202511/24 BOJ \353\247\210\355\224\274\354\225\204.md" @@ -0,0 +1,109 @@ +```java +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.util.Arrays; +import java.util.StringTokenizer; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static int total,target,ans; + static int[] points; + static int[][] arr; + static boolean[] alive; + + public static void main(String[] args) throws IOException { + + init(); + process(); + print(); + + } + + private static void init() throws IOException{ + total = Integer.parseInt(br.readLine()); + points = new int[total]; + alive = new boolean[total]; + arr = new int[total][total]; + ans = 0; + + Arrays.fill(alive, true); + + StringTokenizer st = new StringTokenizer(br.readLine()); + for (int i = 0; i < total; i++) { + points[i] = Integer.parseInt(st.nextToken()); + } + + for (int i = 0; i < total; i++) { + st = new StringTokenizer(br.readLine()); + for (int j = 0; j < total; j++) { + arr[i][j] = Integer.parseInt(st.nextToken()); + } + } + + target = Integer.parseInt(br.readLine()); + } + + private static void process() throws IOException { + + processDay(0,total); + } + + private static void processDay(int nightCnt, int cnt) { + if (cnt%2 == 0) { + for (int i = 0; i < total; i++) { + if ( i != target && alive[i]) { + // 임의로 한명 죽임 + alive[i] = false; + for (int j = 0; j < total; j++) { + points[j] += arr[i][j]; + } + processDay(nightCnt+1,cnt-1); + + //원상복구 + alive[i] = true; + for (int j = 0; j < total;j++) { + points[j] -= arr[i][j]; + } + + } + } + } else { + if (cnt == 1) { + ans = Math.max(ans, nightCnt); + return; + } + + int highest = Integer.MIN_VALUE; + int highestIdx = -1; + for (int i = 0; i < total; i++) { + if (!alive[i]) continue; + if (points[i] > highest) { + highest = points[i]; + highestIdx = i; + } + } + + if (highestIdx == target) { + ans = Math.max(ans, nightCnt); + return; + } + + alive[highestIdx] = false; + processDay(nightCnt,cnt-1); + alive[highestIdx] = true; + + } + + } + + + + + + private static void print() { + System.out.println(ans); + } + +} +```