-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1048.cpp
More file actions
48 lines (43 loc) · 1.02 KB
/
1048.cpp
File metadata and controls
48 lines (43 loc) · 1.02 KB
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
/*************************************************************************
> File Name: 1048.cpp
> Author: dulun
> Mail: [email protected]
> Created Time: 2016年03月06日 星期日 16时37分29秒
************************************************************************/
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#define LL long long
using namespace std;
const int N = 1086;
int dp[N][N];
int a[N];
int sum[N];
int main()
{
int n;
cin>>n;
for(int i = 1; i <= n; i++)
{
cin>>a[i];
sum[i] = sum[i-1]+a[i];
}
for(int l = 2; l <= n; l++)
{
for(int i = 1; i <= n - l + 1; i++)
{
int j = i+l - 1;
int min = 99999999;
for(int k = i; k < j; k++)
{
if(dp[i][k]+dp[k+1][j] + sum[j] - sum[i-1] < min)
min = dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1];
}
dp[i][j] = min;
}
}
cout<<dp[1][n];
return 0;
}