提交时间:2024-07-17 11:06:46
运行 ID: 156390
#include<iostream> using namespace std; long long n, ls[410], f[410][410], S[410]; const long long inf = 1e16; int main(){ cin >> n; for(int i = 1; i <= n; i++){ cin >> ls[i]; S[i] = ls[i] + S[i-1]; } for(int len = 2; len <= n; len++){ for(int i = 1; i <= n-len+1; i++){ int j = i + len - 1; f[i][j] = inf; for(int k = i; k < j; k++){ f[i][j] = min(S[j] - S[i-1] + f[i][k] + f[k+1][j], f[i][j]); } } } cout << f[1][n]; return 0; }