-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathLuogu_P_1063.cpp
31 lines (31 loc) · 911 Bytes
/
Luogu_P_1063.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#include <bits/extc++.h>
using namespace std;
namespace pbds = __gnu_pbds;
using ui = unsigned int;
using uli = unsigned long long int;
using li = long long int;
ui dp(size_t l, size_t r, vector<ui> const& a) {
static vector<vector<ui>> ans(a.size(), vector<ui>(a.size(), -1));
if (ans[l][r] != -1) return ans[l][r];
ans[l][r] = 0;
for (size_t mid = l + 1; mid < r; ++mid)
ans[l][r] =
max(ans[l][r], dp(l, mid, a) + dp(mid, r, a) + a[l] * a[mid] * a[r]);
return ans[l][r];
}
int main(void) {
ios::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr);
size_t n;
cin >> n;
vector<ui> a(n << 1);
for (size_t i = 0; i < n; ++i) cin >> a[i];
copy(a.begin(), a.begin() + n, a.begin() + n);
#ifdef debug
for (ui const& i : a) cout << i << ' ';
cout << '\n';
#endif
ui ans = 0;
for (size_t i = 0; i < n; ++i) ans = max(ans, dp(i, i + n, a));
cout << ans;
return 0;
}