Description
Input
Output
Sample Input
Sample1:
3
1 2 3
Sample2:
9
1 3 2 4 8 6 9 5 7
Sample Output
Sample1:
3
Sample2:
5
Data Constraint
Solution
最长不下降子序列(N log N)或者直接set暴力模拟再用权值线段树或splay维护即可。
Code1
#include<cstdio>
#include<cstring>
#include<set>
#include<cmath>
#include<algorithm>
#define inf 2147483647
#define N 100010
using namespace std;
int n,x,ans;
multiset<int> t;
multiset<int>::iterator it;
int main(){
scanf("%d",&n);
t.insert(inf);
for(int i=1;i<=n;i++){
scanf("%d",&x);
it=t.lower_bound(x);
if(*it==inf) ans++;
else t.erase(it);
t.insert(x);
}
printf("%d",ans);
return 0;
}
Code2
var
i,n,l,r,mid,op,ss:longint;
a,b:array[1..100000]of longint;
begin
readln(n);
for i:=1 to n do read(a[i]);
for i:=1 to n do
begin
if (op=0)or(a[i]>b[op])then
begin
inc(op);
b[op]:=a[i];
end
else
begin
l:=1;
r:=op;
ss:=0;
while l<=r do
begin
mid:=(l+r)div 2;
if a[i]<b[mid] then
begin
ss:=mid;
r:=mid-1;
end
else l:=mid+1;
end;
b[ss]:=a[i];
end;
end;
writeln(op);
end.
作者:zsjzliziyang
QQ:1634151125
转载及修改请注明
本文地址:https://blog.csdn.net/zsjzliziyang/article/details/81843096