From 40672deff934699400d3bd5b53400fc645ceeb4a Mon Sep 17 00:00:00 2001 From: lkhyun <102892446+lkhyun@users.noreply.github.com> Date: Sat, 14 Jun 2025 16:11:24 +0900 Subject: [PATCH] =?UTF-8?q?[20250614]=20BOJ=20/=20G3=20/=20=ED=96=89?= =?UTF-8?q?=EB=A0=AC=20=EA=B3=B1=EC=85=88=20=EC=88=9C=EC=84=9C=20/=20?= =?UTF-8?q?=EC=9D=B4=EA=B0=95=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...1\354\205\210 \354\210\234\354\204\234.md" | 40 +++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 "lkhyun/202506/14 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" diff --git "a/lkhyun/202506/14 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" "b/lkhyun/202506/14 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" new file mode 100644 index 00000000..5a0da871 --- /dev/null +++ "b/lkhyun/202506/14 BOJ G3 \355\226\211\353\240\254 \352\263\261\354\205\210 \354\210\234\354\204\234.md" @@ -0,0 +1,40 @@ +```java +import java.io.*; +import java.util.*; + +public class Main { + static BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); + static BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(System.out)); + static StringTokenizer st; + static int N; + static int[] rows; + static int[] cols; + static int[][] dp; + + public static void main(String[] args) throws IOException { + N = Integer.parseInt(br.readLine()); + rows = new int[N+1]; + cols = new int[N+1]; + for (int i = 1; i <= N; i++) { + st = new StringTokenizer(br.readLine()); + rows[i] = Integer.parseInt(st.nextToken()); + cols[i] = Integer.parseInt(st.nextToken()); + } + dp = new int[N+1][N+1]; + + for (int len = 2; len <= N; len++) { //구간 + for (int i = 1; i <= N - len + 1; i++) { //시작점 + int j = i + len - 1; //끝점 + dp[i][j] = Integer.MAX_VALUE; + + for (int k = i; k < j; k++) { //분할지점 + int num = dp[i][k] + dp[k+1][j] + rows[i]*cols[k]*cols[j]; + dp[i][j] = Math.min(dp[i][j], num); + } + } + } + bw.write(dp[1][N] + "\n"); + bw.close(); + } +} +```