1274:【例9.18】合并石子
作者:互联网
1 #include<iostream> 2 #include<cstdio> 3 #include<cstring> 4 #include<algorithm> 5 using namespace std; 6 7 const int N=105; 8 int a[N],f[N][N]; 9 int main(){ 10 int n; 11 cin>>n; 12 for(int i=1;i<=n;i++){ 13 scanf("%d",&a[i]); 14 a[i]+=a[i-1]; 15 } 16 memset(f,127,sizeof(f)); 17 for(int i=1;i<=n;i++)f[i][i]=0; 18 for(int i=n-1;i>0;i--){ 19 for(int j=i+1;j<=n;j++){ 20 for(int k=i;k<j;k++){ 21 f[i][j]=min(f[i][j],f[i][k]+f[k+1][j]+a[j]-a[i-1]); 22 } 23 } 24 } 25 cout<<f[1][n]; 26 return 0; 27 }
标签:std,10,9.18,int,合并,石子,1274,include 来源: https://www.cnblogs.com/sxrekord/p/merge_stones.html