洛谷1020 导弹拦截

https://www.luogu.org/problem/show?pid=P1020

第一问数列取反之后用类似求LIS的O(nlogn)算法就可以了。
第二问的关键在于Dilworth定理,就这题而言可以表述成:

一个数列划分成最少的最长不升子序列数==这个数列的最长上升子序列长度

也就是说求一下LIS就做完了。
似乎第二问也可以贪心做,但是知道定理的情况下显然是求LIS更容易些……

#include <bits/stdc++.h>
using namespace std;

const int maxn = 1e5+5;
const int INF = 0x3f3f3f3f;
int a[maxn], f[maxn], x, cnt;

int main()
{
    int n = 0;
    while (~scanf("%d", &a[n]))
    {
        a[n] = -a[n];
        ++n;
    }
    fill(f, f+n, 0);
    for (int i = 0; i < n; ++i)
        *upper_bound(f, f+n, a[i]) = a[i];
    printf("%d\n", lower_bound(f, f+n, 0) - f);
    for (int i = 0; i < n; ++i)
        a[i] = -a[i];
    fill(f, f+n, INF);
    for (int i = 0; i < n; ++i)
        *lower_bound(f, f+n, a[i]) = a[i];
    printf("%d\n", lower_bound(f, f+n, INF) - f);
    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值