其他分享
首页 > 其他分享> > NOIP第一阶段成绩总结

NOIP第一阶段成绩总结

作者:互联网

联赛模拟测试33

阶段排名 1

合并集合

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