-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathboj.11066.cc
56 lines (48 loc) · 1.18 KB
/
boj.11066.cc
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_SIZE = 1e9;
void solve()
{
int k, files[500], dpCost[500][500] = {{0}}, dpSize[500][500] = {{0}};
// dp[i][j] => minimum sum from i to j
cin>>k;
for(int i = 0; i<k; ++i)
{
cin>>files[i];
}
for(int i = 0; i<k; ++i)
{
dpSize[i][i] = files[i];
}
for(int size = 2; size<=k; ++size)
{
for(int start = 0, end = start + size - 1;
end < k; end = ++start + size - 1)
{
// cout<<start<<" "<<end<<"\n";
dpCost[start][end] = MAX_SIZE;
for(int mid = start; mid<end; ++mid)
{
dpCost[start][end] = min(dpCost[start][end],
dpCost[start][mid] + dpCost[mid+1][end]
+ dpSize[start][mid] + dpSize[mid+1][end]);
}
dpSize[start][end] = dpSize[start][start] + dpSize[start+1][end];
}
}
cout<<dpCost[0][k-1]<<"\n";
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin>>t;
while(t--)
{
solve();
}
return 0;
}