#include<iostream>
#include<vector>
#include<queue>
#include<cstdio>
using namespace std;
int n;
const int INF = 999999999;
int a[1005];
int dp[1005][1005];
int sum[1005];
int main()
{
cin >> n;
for(int i = 1;i <= n;i++){
cin >> a[i];
sum[i] = sum[i-1] + a[i];
}
for(int len = 2;len <= n;len++){
for(int i = 1;i + len - 1 <= n;i++){
int j = i + len - 1;
dp[i][j] = INF;
for(int k = i ;k < j;k++){
dp[i][j] = min(dp[i][k]+dp[k+1][j]+sum[j]-sum[i-1],dp[i][j]);
}
}
}
cout << dp[1][n] << endl;
}
CCFCSP压缩编码
最新推荐文章于 2021-11-04 18:36:43 发布