rt:
思路是这样的:
开一个栈,每次取栈顶元素top和读到的元素x做比较,如果x > top 则将x入栈;如果x < top则二分查找栈中的比x大的第1个数,并用x替换它。 最长序列长度即为栈的大小top。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
using namespace std;
const int N=10010;
int n,stk[N],top=0;
int main(){
ios::sync_with_stdio(0);
cin>>n;
for(int i=1;i<=n;++i){
int x;
cin>>x;
if(x>stk[top]){stk[++top]=x;continue;}
int pos=lower_bound(stk+1,stk+top+1,x)-stk;
stk[pos]=x;
}
cout<<top<<'\n';
return 0;
}