**思维LIS——最小拦截系统
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;
}
本文深入探讨了思维LIS(Longest Increasing Subsequence)算法,一种用于求解拦截系统最少数目的高效算法。通过实例说明如何利用LIS算法确定最少的拦截系统数量,即求解最长上升子序列的长度。
762

被折叠的 条评论
为什么被折叠?



