목록문제 (388)
sm 기술 블로그
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); int N = Integer.parseInt(br.readLine()); int[][] rc = new int[N][2]; int[][] dp = new int[N][N]; for (int i = 0; i < N; i++) { String[] tmp = br.readLine().split(" "); rc[i][0] = Integer.parseInt(tmp[0]); rc[i][1]..
본 코드는 pypy3로 제출해야 합니다. import sys input = sys.stdin.readline N = int(input()) rc = [list(map(int, input().split())) for _ in range(N)] DP = [[0]*N for _ in range(N)] for i in range(1, N): for x in range(N-i): y = i + x DP[x][y] = 2 ** 32 for k in range(x, y): DP[x][y] = min(DP[x][y], DP[x][k] + DP[k+1][y] + rc[x][0] * rc[k][1] * rc[y][1]) print(DP[0][-1]) 문제요약 행렬의 곱셈 연산이 제일 적게 이행하는 최솟값을 구하라. 설명 ..
import java.util.*; import java.io.*; class Main { public static void main(String[] args) throws IOException { BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); StringBuilder sb = new StringBuilder(); int T = Integer.parseInt(br.readLine()); for (int m = 0; m < T; m++) { int K = Integer.parseInt(br.readLine()); int[] page = new int[K + 1]; String[] tmp = br.readLine().spl..
import sys input = sys.stdin.readline T = int(input()) result = [] for _ in range(T): K = int(input()) page = [0] + list(map(int, input().split())) sumPage = [0 for _ in range(K+1)] for i in range(1, K+1): sumPage[i] = sumPage[i-1] + page[i] DP = [[0]*(K+1) for _ in range(K+1)] for i in range(2, K+1): for j in range(1, K+2-i): DP[j][j+i-1] = min([DP[j][j+k] + DP[j+k+1][j+i-1] for k in range(i-1)..