代码
#include <bits/stdc++.h>
using namespace std;
const int N = 210;
int n;
int a[N], b[N];
int f[N][N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++ )
{
cin >> a[i];
a[i + n] = a[i];
}
for (int i = 1; i <= 2 * n; i ++ )
{
b[i] = a[i + 1];
}
b[2 * n] = a[1];
for (int len = 2; len <= n; len ++ )
{
for (int i = 1; i + len - 1 <= 2 * n; i ++ )
{
int l = i, r = i + len - 1;
for (int mid = l; mid < r; mid ++ )
{
f[l][r] = max(f[l][r], f[l][mid] + f[mid + 1][r] + a[l] * b[r] * b[mid]);
}
}
}
int res = 0;
for (int i = 1; i <= n; i ++ )
{
res = max(res, f[i][i + n - 1]);
}
cout << res << endl;
}