0
1
mirror of https://git.sb/baoshuo/OI-codes.git synced 2024-09-16 20:05:26 +00:00

P1063 [NOIP2006 提高组] 能量项链

R73362890
This commit is contained in:
Baoshuo Ren 2022-04-07 09:22:58 +08:00
parent f5822295a7
commit 42d532b182
Signed by: baoshuo
GPG Key ID: 70F90A673FB1AB68

35
Luogu/P1063/P1063.cpp Normal file
View File

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