0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-11-27 13:56:26 +00:00
Baoshuo Ren 2022-04-06 16:37:01 +08:00
parent dd0c2a1704
commit 9b611935f5
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

33
AcWing/282/282.cpp Normal file
View File

@ -0,0 +1,33 @@
#include <iostream>
using std::cin;
using std::cout;
const char endl = '\n';
const int N = 305;
int n, a[N], sum[N], f[N][N];
int main() {
std::ios::sync_with_stdio(false);
cin >> n;
for (int i = 1; i <= n; i++) {
cin >> a[i];
sum[i] = sum[i - 1] + a[i];
}
for (int i = 2; i <= n; i++) {
for (int l = 1, r = i; r <= n; l++, r++) {
f[l][r] = 0x3f3f3f3f;
for (int k = l; k < r; k++) {
f[l][r] = std::min(f[l][r], f[l][k] + f[k + 1][r] + sum[r] - sum[l - 1]);
}
}
}
cout << f[1][n] << endl;
return 0;
}