-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboj_11066.cpp
More file actions
37 lines (31 loc) · 811 Bytes
/
boj_11066.cpp
File metadata and controls
37 lines (31 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
//<11066>번 : <파일 합치기>
#include <bits/stdc++.h>
#define INF 5000000000000
using namespace std;
int t, n;
long long d[500][500] = {};
long long s[500][500] = {};
int main()
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cin >> t;
while(t--) {
cin >> n;
fill(s[0], s[500], INF);
for(int i = 0; i < n; i++) {
cin >> d[i][i];
s[i][i] = 0;
}
for(int range = 2; range <= n; range++) {
for(int i = 0; i <= n - range; i++) {
int j = i + range - 1;
d[i][j] = d[i][j-1] + d[j][j];
for(int k = i; k < j; k++)
s[i][j] = min(s[i][j], s[i][k] + s[k+1][j] + d[i][j]);
}
}
cout << s[0][n-1] << '\n';
}
return 0;
}