NOIP第一阶段成绩总结
作者:互联网
联赛模拟测试33
阶段排名 1
合并集合
-
环状所以复制一遍放在后面,区间DP一下就好了,f[i][j]表示区间i到j所获收益的最大值,枚举断点转移
-
s[i][j]表示将区间i到j的集合的元素个数,就是不相同的数的个数,考场上用的bitset,其实开个桶,n2扫一遍就行了
Show Code
#include <cstdio>
#include <algorithm>
const int N = 605;
int read(int x = 0, int f = 1, char c = getchar()) {
for (; c < '0' || c > '9'; c = getchar())
if (c == '0') f = -1;
for (; c >= '0' && c <= '9'; c = getchar())
x = x * 10 + c - '0';
return x * f;
}
int n, s[N][N], f[N][N], ans, a[N], b[N<<1];
int main() {
freopen("merge.in", "r", stdin);
freopen("merge.out", "w", stdout);
n = read();
for (int i = 1; i <= n; ++i)
a[i] = a[i+n] = read();
for (int i = 1; i <= n + n; ++i)
for (int j = i; j <= n + n && j <= i + n - 1; ++j)
s[i][j] = s[i][j-1] + (b[a[j]] != i), b[a[j]] = i;
for (int d = 2; d <= n; ++d)
for (int i = 1, j; (j = i + d - 1) < n * 2; ++i)
for (int k = i; k < j; ++k)
f[i][j] = std::max(f[i][j], f[i][k] + f[k+1][j] + s[i][k] * s[k+1][j]);
for (int i = 1; i <= n; ++i)
ans = std::max(ans, f[i][i+n-1]);
printf("%d\n", ans);
return 0;
}
ZYB建围墙
ZYB和售货机 (Unaccpeted)
ZYB玩字符串 (Unnaccpeted)
标签:第一阶段,include,ZYB,NOIP,int,个数,区间,成绩,getchar 来源: https://www.cnblogs.com/Z8875/p/14005389.html