#include<bits/stdc++.h>usingnamespace std;constint N =310;intp[N];intf[N][N];intmain() {int n; cin >> n;for (int i =1; i <= n; i ++) { cin >>p[i],p[i] +=p[i -1]; }for (int len =2; len <= n; len ++) {for (int i =1; i + len -1<= n; i ++) {int j = i + len -1;f[i][j] =1e8;for (int k = i; k <= j; k ++) {f[i][j] =min(f[i][j],f[i][k] +f[k +1][j] +p[j] -p[i -1]); } } } cout <<f[1][n] << endl;return0;}
classSolution {public:intmaxCoins(vector<int>& nums) {int n =nums.size(); vector<int>a(n +2,1);for (int i =1; i <= n; i ++) a[i] =nums[i -1]; vector<vector<int>>f(n +2,vector<int>(n +2,0));for (int len =3; len <= n +2; len ++) {for (int i =0; len + i -1<= n +1; i ++) {int j = len + i -1;for (int k = i +1; k < j; k ++) {f[i][j] =max(f[i][j],f[i][k] +f[k][j] +a[k] *a[i] *a[j]); } } }returnf[0][n +1]; }};
classSolution {public:intgetMoneyAmount(int n) { vector<vector<int>>f(n +2,vector<int>(n +2));for (int len =2; len <= n; len ++) {for (int i =1; i + len -1<= n; i ++) {int j = i + len -1;f[i][j] =1e8;for (int k = i; k <= j; k ++) {f[i][j] =min(f[i][j],max(f[i][k -1],f[k +1][j]) + k); } } }returnf[1][n]; }};