最长上升子序列模版

来源:互联网 发布:大数据可视化解决方案 编辑:程序博客网 时间:2024/05/16 11:44
#include<iostream>#include<cstdio>#define maxn 100005#define INF 0x7fffffffusing namespace std;int main(){    int n;    while(scanf("%d",&n)!=EOF)    {        int stack[maxn];        int top=0,tempt;        stack[top]=-1;        for(int i=0;i<n;i++)        {            scanf("%d",&tempt);            if(tempt>stack[top])            {                stack[++top]=tempt;            }            else            {                int low=1,high=top,mid;                while(low<=high)//用二分找比tempt大的第一个数                {                    mid=(low+high)/2;                    if(stack[mid]<tempt)//这里得想清楚                    {                        low=mid+1;                    }                    else                    high=mid-1;                }                stack[low]=tempt;            }        }        printf("%d\n",top);    }return 0;}
	
				
		
原创粉丝点击