http://tyvj.cn/p/1055
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
const int maxn = 1000 + 5;
int f[maxn][maxn];
//设f[i][j]为合并[i..j]的最小费用
//f[i][j] = min{f[i][j], f[i][k]+f[k+1][j]+a[j]-a[i-1] | i<=k<j}
int a[maxn];
int main ()
{
int n;
scanf("%d", &n);
int tot = 0;
for (int i=1;i<=n;i++)
{
int aa;
scanf("%d", &aa);
tot += aa;
a[i] = tot;
}
memset(f,20,sizeof(f));
for (int i=1;i<=n;i++) f[i][i] = 0;
for (int i=n-1;i>0;i--)
{
for (int j=i+1;j<=n;j++)
{
for (int k=i;k<=j-1;k++)
{
f[i][j] = min(f[i][j], f[i][k]+f[k+1][j]+a[j]-a[i-1]);
}
}
}
printf("%d\n", f[1][n]);
return 0;
}