baekjoon 20260417

This commit is contained in:
songyc macbook 2026-04-17 13:26:21 +09:00
parent e10b8d91c0
commit 9025f098c1
2 changed files with 29 additions and 0 deletions

View File

@ -0,0 +1 @@
print("\n".join([" "*i + "*"*(2*N-1-2*i) if i < N else " "*(2*(N-i-1)+i) + "*"*(2*N-1-2*(2*(N-i-1)+i)) for N in [int(input())] for i in range(2*N-1)]))

View File

@ -0,0 +1,28 @@
import { start } from "repl";
export {};
const input = require("fs").readFileSync(0).toString().trim().split("\n");
const N: number = Number(input[0]);
let rc: number[][] = []
for(let i=1; i<=N; i++) rc.push(input[i].split(" ").map(Number));
let dp: number[][] = Array.from({length : N}, () => new Array(N).fill(0));
for(let len=2; len<=N; len++) {
for(let start=0; start<=N-len; start++) {
const end: number = start + len - 1;
dp[start][end] = Number.MAX_VALUE;
for(let k=start; k<end; k++) {
const leftOp: number = dp[start][k];
const rightOp: number = dp[k+1][end];
const mergeOp: number = rc[start][0]*rc[k][1]*rc[end][1];
dp[start][end] = Math.min(dp[start][end], leftOp + rightOp + mergeOp);
}
}
}
console.log(dp[0][N-1]);