[AcWing 320] 能量项链
作者:互联网
点击查看代码
#include<iostream>
#include<cstring>
using namespace std;
typedef long long LL;
const int N = 210;
const int INF = 0x3f3f3f3f;
int n;
int w[N];
LL f[N][N];
int main()
{
cin >> n;
for (int i = 1; i <= n; i ++) {
cin >> 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]);
}
LL res = 0;
for (int i = 1; i <= n; i ++)
res = max(res, f[i][i + n]);
cout << res << endl;
return 0;
}
- 状态表示
\(f[i][j]\) 表示将第 \(i\) 个珠子到第 \(j\) 个珠子合并的最大能量 - 状态计算
用 \(k\) 表示区间 \([l,r]\) 和 \([k,r]\) 合并的交点处
\(f[l][r] = max(f[l][k] + f[k][r] + w[l] \cdot w[k] \cdot w[r])\) - 枚举区间长度时,区间长度最小为 3,最大为 \(n + 1\),表示 \(l = r\)
标签:const,int,LL,long,320,len,项链,include,AcWing 来源: https://www.cnblogs.com/wKingYu/p/16456445.html