# include<stdio.h>
# include<string.h>
int dp[100001],a[100001];
int find(int begin,int end,int num)
{
int x,y,m;
x=begin;
y=end;
if(dp[x]>=num)
return x;
while(x<=y)
{
m=(x+y)/2; //printf("%d ",m);
if(dp[m]>=num)
{
if(dp[m-1]<num)
return m;
else
y=m-1;
}
else
{
if(dp[x]>=num)
return x;
else
x=m+1;
}
}
}
int main()
{
int n;
//freopen("2.txt","r",stdin);
while(~scanf("%d",&n))
{
if(n==0)
continue;
int i,p=1,m;
scanf("%d",&a[0]);
dp[1]=a[0];
for(i=1;i<n;i++)
{
scanf("%d",&a[i]);
if(a[i]>dp[p])
dp[++p]=a[i];
else
{
m=find(1,p,a[i]);//printf("%d ",m);
dp[m]=a[i];
}
}
printf("%d\n",p);
}
return 0;
}
单调递增子序列+二分优化
最新推荐文章于 2021-07-05 11:26:37 发布