const int N = 55;
ll w[N], f[N][N][N],n;
void add(ll a[], ll b[])
{
static ll c[N];
memset(c, 0, sizeof c);
for (int i = 0, t = 0;i < N;i++)
{
t += b[i] + a[i];
c[i] = t % 10;
t = t / 10;
}
memcpy(a, c, sizeof c);
}
void pri(ll a[])
{
int idx = N - 1;
while (idx && !a[idx])idx--;
while (idx >= 0)printf("%lld", a[idx--]);
cout << endl;
}
void mul(ll a[], ll b)
{
static ll c[N];
ll t = 0;
memset(c, 0, sizeof c);
for (int i = 0;i < N;i++)
{
t += a[i] * b;
c[i] = t % 10;
t /= 10;
}
//pri(c);
memcpy(a, c, sizeof c);
}
int cmp(ll a[], ll b[])
{
ff(i, N-1,0)
{
if (a[i] > b[i])return 1;
else if (a[i] < b[i])return -1;
}
return 0;
}
int main()
{
//freopen("in.txt", "r", stdin);
while (cin >> n)
{
f(i, 1, n)cin >> w[i];
ll tmp[N];
f(len,3,n)//枚举区间长度
{
for (int l = 1;l + len - 1 <= n;l++)//枚举起点
{
int r = l + len - 1;
f[l][r][N - 1] = 1;//设为无穷大
f(k, l + 1, r - 1)
{
memset(tmp, 0, sizeof tmp);
tmp[0] = w[l];
//pri(tmp);
mul(tmp, w[k]);
mul(tmp, w[r]);
add(tmp, f[l][k]);
add(tmp, f[k][r]);
if (cmp(f[l][r], tmp) > 0)memcpy(f[l][r], tmp, sizeof tmp);
}
}
}
pri(f[1][n]);
}
return 0;
}
AcWing 1069. 凸多边形的划分(区间dp+高精度)
最新推荐文章于 2022-02-15 13:08:09 发布