https://www.acmicpc.net/problem/11066
#include <iostream>
#include <algorithm>
#include <vector>
#include <stack>
#include <limits.h>
using namespace std;
int main() {
int T; cin >> T;
for (int t = 1; t <= T; t++) {
int N; cin >> N;
int cost[502][502] = { 0 };
int sum[502] = { 0 };
vector<int> list = { 0 };
for (int i = 1; i <= N; i++) {
int n; cin >> n;
list.push_back(n);
sum[i] = sum[i - 1] + n;
}
for (int k = 1; k < N; k++) {
for (int i = 1; i <= N - k; i++) {
int j = i + k;
cost[i][j] = INT_MAX;
for (int f = i; f < j; f++) {
int temp = cost[i][f] + cost[f + 1][j] + sum[j] - sum[i - 1];
if (temp < cost[i][j]) {
cost[i][j] = temp;
}
}
}
}
cout << cost[1][N] << endl;
}
return 0;
}
'전공공부 > 코딩테스트' 카테고리의 다른 글
(c++) 백준 "10250) ACM 호텔" (0) | 2022.06.02 |
---|---|
(c++) 프로그래머스 "베스트앨범" (0) | 2022.05.31 |
(c++) 1209) Sum (0) | 2022.05.28 |
(c++) SWEA "1215) 회문1" (0) | 2022.05.28 |
(c++) SWEA "2806) N-Queen" (0) | 2022.05.28 |