From bcf65e566e4b6c46c1f9ab34559c1c28d8cc9857 Mon Sep 17 00:00:00 2001 From: zinnnn37 Date: Sun, 22 Feb 2026 22:56:09 +0900 Subject: [PATCH] =?UTF-8?q?[20260222]=20BOJ=20/=20G3=20/=20=EA=B4=84?= =?UTF-8?q?=ED=98=B8=20=EC=B6=94=EA=B0=80=ED=95=98=EA=B8=B0=20/=20?= =?UTF-8?q?=EA=B9=80=EB=AF=BC=EC=A7=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...24\352\260\200\355\225\230\352\270\260.md" | 70 +++++++++++++++++++ 1 file changed, 70 insertions(+) create mode 100644 "zinnnn37/202602/22 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" diff --git "a/zinnnn37/202602/22 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" "b/zinnnn37/202602/22 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" new file mode 100644 index 00000000..9c22e890 --- /dev/null +++ "b/zinnnn37/202602/22 BOJ G3 \352\264\204\355\230\270 \354\266\224\352\260\200\355\225\230\352\270\260.md" @@ -0,0 +1,70 @@ +```java +import java.io.*; + +public class BJ_16637_괄호_추가하기 { + + private static final BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + private static final BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + + private static int N, ans; + private static String line; + private static int[] nums; + private static char[] ops; + + public static void main(String[] args) throws IOException { + init(); + sol(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + ans = Integer.MIN_VALUE; + + int numCnt = N / 2 + 1; + nums = new int[numCnt]; + ops = new char[numCnt - 1]; + + line = br.readLine(); + for (int i = 0; i < N; i++) { + if (i % 2 == 0) { + nums[i / 2] = line.charAt(i) - '0'; + } else { + ops[i / 2] = line.charAt(i); + } + } + } + + private static void sol() throws IOException { + rec(0, nums[0]); + + bw.write(ans + ""); + bw.flush(); + bw.close(); + br.close(); + } + + private static void rec(int idx, int cur) { + if (idx >= ops.length) { + ans = Math.max(ans, cur); + return; + } + + int next = nums[idx + 1]; + int noBracket = calc(cur, next, ops[idx]); + rec(idx + 1, noBracket); + + if (idx + 1 < ops.length) { + int bracketVal = calc(next, nums[idx + 2], ops[idx + 1]); + int withBracket = calc(cur, bracketVal, ops[idx]); + rec(idx + 2, withBracket); + } + } + + private static int calc(int a, int b, char op) { + if (op == '+') return a + b; + if (op == '-') return a - b; + return a * b; + } + +} +``` \ No newline at end of file