#include<iostream> #include<string.h> using namespace std; const int N=310; int n; int s[N]; int f[N][N]; int main() { scanf("%d",&n); memset(f,0x3f,sizeof f); for(int i=1;i<=n;i++) { int x; scanf("%d",&x); s[i]=s[i-1]+x; f[i][i]=0; } for(int len=2;len<=n;len++)//区间长度 { for(int l=1;l+len-1<=n;l++)//状态 枚举区间起点 { int r=l+len-1; for(int k=l;k<r;k++)//决策 f[l][r]=min(f[l][r],f[l][k]+f[k+1][r]+s[r]-s[l-1]); } } printf("%d",f[1][n]); return 0; }
标签:std,main,int,石子,合并,include From: https://www.cnblogs.com/tolter/p/17295870.html