From a9e180105b63d770bfa110ea638fcd5dca192053 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Wed, 10 Dec 2025 16:12:04 +0900 Subject: [PATCH] =?UTF-8?q?[20251210]=20BOJ=20/=20G4=20/=20=EA=B0=80?= =?UTF-8?q?=EC=9E=A5=20=EA=B8=B4=20=EB=B0=94=EC=9D=B4=ED=86=A0=EB=8B=89=20?= =?UTF-8?q?=EB=B6=80=EB=B6=84=20=EC=88=98=EC=97=B4=20/=20=ED=95=9C?= =?UTF-8?q?=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...0\353\266\204 \354\210\230\354\227\264.md" | 61 +++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 "Ukj0ng/202512/10 BOJ G4 \352\260\200\354\236\245 \352\270\264 \353\260\224\354\235\264\355\206\240\353\213\211 \353\266\200\353\266\204 \354\210\230\354\227\264.md" diff --git "a/Ukj0ng/202512/10 BOJ G4 \352\260\200\354\236\245 \352\270\264 \353\260\224\354\235\264\355\206\240\353\213\211 \353\266\200\353\266\204 \354\210\230\354\227\264.md" "b/Ukj0ng/202512/10 BOJ G4 \352\260\200\354\236\245 \352\270\264 \353\260\224\354\235\264\355\206\240\353\213\211 \353\266\200\353\266\204 \354\210\230\354\227\264.md" new file mode 100644 index 00000000..300e12f3 --- /dev/null +++ "b/Ukj0ng/202512/10 BOJ G4 \352\260\200\354\236\245 \352\270\264 \353\260\224\354\235\264\355\206\240\353\213\211 \353\266\200\353\266\204 \354\210\230\354\227\264.md" @@ -0,0 +1,61 @@ +``` +import java.io.*; +import java.util.*; + +public class Main { + 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[] arr, dp, dp1, dp2; + private static int N, answer; + + public static void main(String[] args) throws IOException { + init(); + DP(); + + bw.write(answer + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + N = Integer.parseInt(br.readLine()); + + StringTokenizer st = new StringTokenizer(br.readLine()); + arr = new int[N]; + dp = new int[N]; + dp1 = new int[N]; + dp2 = new int[N]; + + for (int i = 0; i < N; i++) { + arr[i] = Integer.parseInt(st.nextToken()); + } + + Arrays.fill(dp1, 1); + Arrays.fill(dp2, 1); + } + + private static void DP() { + for (int i = 1; i < N; i++) { + for (int j = 0; j < i; j++) { + if (arr[i] > arr[j]) { + dp1[i] = Math.max(dp1[i], dp1[j]+1); + } + } + } + + for (int i = N-2; i >= 0; i--) { + for (int j = N-1; j > i; j--) { + if (arr[i] > arr[j]) { + dp2[i] = Math.max(dp2[i], dp2[j]+1); + } + } + } + + for (int i = 0; i < N; i++) { + dp[i] = dp1[i] + dp2[i] - 1; + answer = Math.max(answer, dp[i]); + } + } +} +```