**思维LIS——最小拦截系统**思维LIS——最小拦截系统**思维LIS——最小拦截系统**思维LIS——最小拦截系统**思维LIS——最小拦截系统**思维LIS——最小拦截系统LIS——最小拦截系

**思维LIS——最小拦截系统

CodeURL

SolveURL

Description

拦截系统:发出的拦截炮弹高度非严格递减,第一发:任意高度即可

来了一系列炮弹,最少需要多少拦截系统

Solution

求最长上升子序列,其长度就是最少的拦截系统设置

例如:

A a b c B d e f C D
其中 A B C D为最长上升子序列
* 拦截了A之后 B C D至少需要需要三个
* a b c <= A 但是不存在 a < b || b < c || a < c否则最长上升子序列不会是A B C D
/*以下为四个拦截系统的目标拦截值*/
* A a b c
* B d e f
* C
* D

Code

#include <bits/stdc++.h>
​
using namespace std;
const int maxn = 3e4 + 1e2;
int dp[maxn],cnt;
int da[maxn];
int main()
{
    int n;
    while(~scanf("%d",&n)){
        cnt = 0;
        for(int i = 1;i <= n;++i)scanf("%d",&da[i]);
        for(int i = 1;i <= n;++i){
            if(da[i] > dp[cnt]){
                dp[++cnt] = da[i];
            }else{
                int aim = lower_bound(dp+1,dp+cnt,da[i]) - (dp+1) + 1;
                //cout<<aim<<endl;
                dp[aim] = da[i];
            }
        }
        cout<<cnt<<"\n";
    }
    return 0;
}
  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值