codeforces 583B B. Once Again...(LIS)

题解 : 我们要注意到一个东西就是说一个序列复制 n 遍一定到 lis 最后一个要么是最大的元素,要么是这个序列中重复最多的元素,这样的话,我们对于 t < n 的情况直接暴力求 lis 就可以,对于 t > n 的情况,我们先复制n遍,再把剩下的出现最多的元素加入到这个序列中去就可以了.

#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

using namespace std;

const int maxn = 1e4 + 10;
int n,t;
int a[maxn] = {0};
int d[maxn] = {0};
int ans = 0;
int len = 0;
int cnt[maxn] = {0};
int mx = 0;
int main () {
    ios_base :: sync_with_stdio(false);
    cin >> n >> t;
    for (int i = 1;i <= n; ++ i) {
        cin >> a[i];
        cnt[a[i]] ++;
        mx = max (cnt[a[i]],mx);
    }
    int N;
    if (t <= n) {
        N = n * t;
    }
    else {
            N = n * n;
    }
    for (int i = 1;i <= N; ++ i) {
        if (i % n)
            a[i] = a[i % n];
        else a[i] = a[n];
    }
    int len = 1;
    d[0] = a[1];
    for (int i = 2;i <= N; ++ i) {
        if (d[len - 1] <= a[i]) {
            d[len ++] = a[i];
        }
        else {
        int pos = upper_bound(d, d + len, a[i]) - d;
            d[pos] = a[i];
        }
    }
    ans = len;
    if (t > n) {
        ans += (t - n) * mx;
    }
    cout << ans << endl;
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值