From b5f5add8f8261f81c78950d795dbabd6811d0b27 Mon Sep 17 00:00:00 2001 From: Ukj0ng <90972240+Ukj0ng@users.noreply.github.com> Date: Thu, 5 Feb 2026 09:37:27 +0900 Subject: [PATCH] =?UTF-8?q?[20260205]=20BOJ=20/=20G3=20/=20=EC=9C=A0?= =?UTF-8?q?=EC=A0=84=EC=9E=90=20/=20=ED=95=9C=EC=A2=85=EC=9A=B1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...3 \354\234\240\354\240\204\354\236\220.md" | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 "Ukj0ng/202602/05 BOJ G3 \354\234\240\354\240\204\354\236\220.md" diff --git "a/Ukj0ng/202602/05 BOJ G3 \354\234\240\354\240\204\354\236\220.md" "b/Ukj0ng/202602/05 BOJ G3 \354\234\240\354\240\204\354\236\220.md" new file mode 100644 index 00000000..59187e93 --- /dev/null +++ "b/Ukj0ng/202602/05 BOJ G3 \354\234\240\354\240\204\354\236\220.md" @@ -0,0 +1,47 @@ +``` +import java.io.*; + +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[][] dp; + + public static void main(String[] args) throws IOException { + init(); + + bw.write(dp[1][dp[0].length-2] + "\n"); + bw.flush(); + bw.close(); + br.close(); + } + + private static void init() throws IOException { + char[] input = br.readLine().toCharArray(); + + dp = new int[input.length+2][input.length+2]; + + int left = 0; + int right = 1; + + while (left <= input.length-2) { + if (input[left] == 'a' && input[right] == 't') dp[left+1][right+1] = 2; + if (input[left] == 'g' && input[right] == 'c') dp[left+1][right+1] = 2; + left++; + right++; + } + + + for (int len = 3; len <= input.length; len++) { + for (int i = 1; i+len-1 <= input.length; i++) { + if ((input[i-1] == 'a' && input[i-2+len] == 't') + || (input[i-1] == 'g' && input[i-2+len] == 'c')) { + dp[i][i+len-1] = dp[i+1][i+len-2]+2; + } + for (int j = i; j < i+len-1; j++) { + dp[i][i+len-1] = Math.max(dp[i][i+len-1], dp[i][j] + dp[j+1][i+len-1]); + } + } + } + } +} +```