HDU-1257-最少拦截系统

链接:https://vjudge.net/problem/HDU-1257

题意:

某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 
怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系统. 

思路:

LIS,原本求下降的子序列,但是可以看成上升子序列的长度。

代码:

#include <iostream>
#include <memory.h>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <queue>
#include <string>
#include <stack>
#include <iterator>

using namespace std;

typedef long long LL;

const int MAXN = 1000 + 10;

int a[MAXN], dp[MAXN];

int main()
{
    int n;
    while (cin >> n)
    {
        for (int i = 1;i <= n;i++)
            cin >> a[i];
        int pos = 1;
        dp[1] = a[1];
        for (int i = 2;i <= n;i++)
        {
            //每次尽量将较小的值压进去
            if (a[i] > dp[pos])
                dp[++pos] = a[i];
            else
            {
                int si = lower_bound(dp + 1, dp + 1 + pos, a[i]) - dp; // 二分实现LIS,
                dp[si] = a[i];
            }
        }
        cout << pos << endl;
    }

    return 0;
}

  

转载于:https://www.cnblogs.com/YDDDD/p/10634006.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值