#include<cstdio>
#include<iostream>
using namespace std;
int n;
int a[9999];
int s[9999],f[9999][999];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
{
scanf("%d",&a[i]);
s[i]=s[i-1]+a[i];
}
for(int i=1;i<=n;i++)
for(int j=1;j<=n;j++)
f[i][j]=99999999;
for(int i=1;i<=n;i++) f[i][i]=0;
for(int p=1;p<=n-1;p++)
for(int i=1;i<=n-p;i++)
{
int j=i+p;
for(int k=i;k<=j-1;k++)
f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+s[j]-s[i-1]);
}
printf("%d",f[1][n]);
return 0;
}
转载于:https://www.cnblogs.com/wspl98765/p/6819907.html