Codeforces #323 D. Once Again... (LIS)

题意:

T<=107N<=100,LIS

分析:

a1,a2,...,anTn,n1.
,n(a1,...,an2),n(anTn+1,...,anT)LIS.
f[i]:=a[i]nLIS
g[i]:=a[i]nLIS
ans=max{f[i]+(T2n)count(ai)+max{g[j],aj>=aij[nTn+1,nT]},i[1,n2]}
ps:count(ai)=cnt of ai in a1,...,an
,,set,sortg[j],ans

代码:

//
//  Created by TaoSama on 2015-10-04
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e5 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, T, a[N], f[N], g[N], h[N], cnt[305];
//f: end i g: start i

int r[N];
bool cmp(int x, int y) {
    return a[x] > a[y];
}

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d", &n, &T) == 2) {
        memset(cnt, 0, sizeof cnt);
        for(int i = 1; i <= n; ++i) {
            scanf("%d", a + i);
            ++cnt[a[i]];
        }
        int t = min(T, n << 1);
        for(int i = 1; i < t; ++i)
            for(int j = 1; j <= n; ++j)
                a[j + i * n] = a[j];

        int ans = 0;
        if(T <= n << 1) {
            memset(h, 0x3f, sizeof h);
            for(int i = 1; i <= n * t; ++i) {
                int k = upper_bound(h + 1, h + n * t + 1, a[i]) - h;
                ans = max(ans, k);
                h[k] = a[i];
            }
        } else {
            memset(h, 0x3f, sizeof h);
            for(int i = 1; i <= n * n; ++i) {
                int k = upper_bound(h + 1, h + n * n + 1, a[i]) - h;
                f[i] = k;
                h[k] = a[i];
            }

            memset(h, 0x3f, sizeof h);
            for(int i = n * n; i; --i) {
                int k = upper_bound(h + 1, h + n * n + 1, -a[i]) - h;
                g[i] = k;
                h[k] = -a[i];
            }

            for(int i = 1; i <= n * n; ++i) r[i] = i;
            sort(r + 1, r + n * n + 1, cmp);
            set<int> s;
            for(int i = 1, j = 1; i <= n * n; ++i) {
                int x = r[i];
                while(j <= n * n && a[r[j]] >= a[r[i]]) s.insert(g[r[j++]]);
                int tmp = f[x] + (T - 2 * n) * cnt[a[x]] + (*s.rbegin());
                ans = max(ans, tmp);
            }
        }
        printf("%d\n", ans);
    }
    return 0;
}

UPD: n,ac,
代码:

//
//  Created by TaoSama on 2015-10-04
//  Copyright (c) 2015 TaoSama. All rights reserved.
//
//#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <algorithm>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <vector>

using namespace std;
#define pr(x) cout << #x << " = " << x << "  "
#define prln(x) cout << #x << " = " << x << endl
const int N = 1e6 + 10, INF = 0x3f3f3f3f, MOD = 1e9 + 7;

int n, T, a[N], g[N];
int cnt[305];

int main() {
#ifdef LOCAL
    freopen("in.txt", "r", stdin);
//  freopen("out.txt","w",stdout);
#endif
    ios_base::sync_with_stdio(0);

    while(scanf("%d%d", &n, &T) == 2) {
        memset(cnt, 0, sizeof cnt);
        int maxv = 0;
        for(int i = 1; i <= n; ++i) {
            scanf("%d", a + i);
            maxv = max(maxv, ++cnt[a[i]]);
        }
        int t = min(T, n);
        for(int i = 1; i < t; ++i)
            for(int j = 1; j <= n; ++j)
                a[j + i * n] = a[j];

        memset(g, 0x3f, sizeof g);
        int ans = 0;
        for(int i = 1; i <= n * t; ++i) {
            int k = upper_bound(g + 1, g + n * t + 1, a[i]) - g;
            ans = max(ans, k);
            g[k] = a[i];
        }

        ans += maxv * (T - t);
        printf("%d\n", ans);
    }
    return 0;
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 2
    评论
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值