Topic links: Click here
And matrix continually multiply like.
represents all the were combined in a way to the maximum bead (matrix).
State transition equation:
Tip: split ring and chain copied doubled, the question becomes merge adjacent beads on the line, each with a length of interval corresponds to a situation in a ring shape.
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
using namespace std;
const int N = 210;
int w[N];
int f[N][N];
int main()
{
int n;
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
{
scanf("%d", &w[i]);
w[i + n] = w[i];
}
for(int len = 3; len <= n + 1; len++)
{
for(int l = 1; l + len - 1 <= 2 * n; l++)
{
int r = l + len - 1;
for(int k = l + 1; k < r; k++)
{
f[l][r] = max(f[l][r], f[l][k] + f[k][r] + w[l] * w[k] * w[r]);
}
}
}
int ans = 0;
for(int i = 1; i <= n; ++i) ans = max(ans, f[i][i + n]);
printf("%d\n", ans);
return 0;
}