poj 3903 最长上升子序列 Stock Exchange

时间:2024-03-28 23:05:56

题目链接:http://poj.org/problem?id=3903

 #include <cstdio>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <queue>
#include <vector>
#define maxn 100005
using namespace std; int stack[maxn];
int a[maxn];
int n; int search_lower_bound(int l,int h,int m){
if(l == h) return h;
int mid = (l + h)/; //printf("%d\n",mid);
if(stack[mid] < m) return search_lower_bound(mid+,h,m);
else return search_lower_bound(l,mid,m);
} int main()
{
if(freopen("input.txt","r",stdin)== NULL) {printf("Error\n"); exit();} while(cin>>n){
for(int i=;i<n;i++) scanf("%d",&a[i]);
int rear = ;
stack[] = a[];
for(int i=;i<n;i++){
if(a[i]>stack[rear]){
rear++;
stack[rear] = a[i];
}
else{
int temp = search_lower_bound(,rear,a[i]);
//printf("%d %d %d\n",temp,stack[temp],a[i]);
stack[temp] = a[i];
}
}
printf("%d\n",rear+);
}
}