mirror of
https://git.sb/baoshuo/OI-codes.git
synced 2024-11-08 13:58:48 +00:00
282. 石子合并
https://www.acwing.com/problem/content/submission/code_detail/13071367/
This commit is contained in:
parent
dd0c2a1704
commit
9b611935f5
33
AcWing/282/282.cpp
Normal file
33
AcWing/282/282.cpp
Normal 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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user