题目传送门
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) a>b?a:b
#define min(a,b) a>b?b:a
int n;int a[1001];int g[1001][1001];int main()
{cin>>n;memset(g,0x3f,sizeof(g));for(int i=1;i<=n;i++){cin>>a[i];a[i]+=a[i-1];g[i][i]=0;}for(int len=2;len<=n;len++){for(int i=1;i<=n-len+1;i++){int j=i+len-1;for(int k=i;k<j;k++){g[i][j]=min(g[i][j],g[i][k]+g[k+1][j]+a[j]-a[i-1]);}}}cout<<g[1][n]<<endl;return 0;
}