整理模板,经典题型。
ACcode:
#include<cstdio>
#include<cstring>
const int NS=110000;
int c[NS],n;
int st[NS],top;
int LIS(int len,int a[])
{
st[top=1]=a[1];
for (int i=2;i<=len;i++)
if (a[i]>st[top]) st[++top]=a[i];
else
{
int mid,low=1,high=top;
while (low<high)
{
mid=(low+high)>>1;
if (st[mid]>=a[i]) high=mid;
else low=mid+1;
}
st[low]=a[i];
}
return top;
}
int main()
{
while (~scanf("%d",&n))
{
for (int i=1;i<=n;i++)
scanf("%d",&c[i]);
printf("%d\n",LIS(n,c));
}
return 0;
}