我的代码
#include<bits/stdc++.h>
using namespace std;
const int N=100005;
const int INF=0x3f3f3f3f;
int a[N],dp[N],vis[N];//vis[i]第i导弹是否已选择
int h;
int main(){
int cnt=0,ans=0,maxn=INT_MIN,n=0;
while(cin>>h) a[n++]=h;
for(int i=1;i<=n;i++) {
dp[i]=1;//dp[i]以i为结尾的最长不上升子序列的长度
for(int j=1;j<=i-1;j++)
if(a[i]<=a[j]) dp[i]=max(dp[i],dp[j]+1); //不能高于即为<=
maxn=max(maxn,dp[i]);
}
cout<<maxn<<endl;
while(cnt<n) {
h=INF;//可拦截的高度
for(int i=1;i<=n;i++){
if(vis[i]==0&&h>a[i]){
h=a[i];//可拦截高度降低
//cout<<h<<" ";
vis[i]=1;
cnt++;//cnt记得加上不然会TLE(第一次就死在这
}
}
ans++;
//cout<<h<<" ";
//cout<<cnt<<" "<<endl;
}
cout<<ans<<endl;
return 0;
}
/*
389 207 155 300 299 170 158 65
6
2
*/