最长不下降子序列
最长不下降子序列
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int n,t,len,a[10005],d[10005];
int main()
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
if(n==0)
{
printf("0\n");
return 0;
}
d[++len]=a[1];
for(int i=2;i<=n;i++)
{
if(a[i]>=d[len])
d[++len]=a[i];
else
{
t=upper_bound(d+1,d+len+1,a[i])-d;
d[t]=a[i];
}
}
printf("%d\n",len);
return 0;
}
Classical is something not fade,but grow more precious with time pass by,so is dream.梦想这东西和经典一样,永远不会因为时间而褪色,反而更显珍贵。