没什么说的,纯裸的LIS,到是二分的感受更明白了点。
#include "stdio.h"
#include "string.h"
#include "math.h"
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
using namespace std;
#define MAXM 1
#define MAXN 1
#define max(a,b) a > b ? a : b
#define min(a,b) a < b ? a : b
#define Mem(a,b) memset(a,b,sizeof(a))
int Mod = 1000000007;
double pi = acos(-1.0);
double eps = 1e-6;
typedef struct{
int f,t,w,next;
}Edge;
Edge edge[MAXM];
int head[MAXN];
int kNum;
int dp[1005];
int num[1005];
int ans, N;
void addEdge(int f, int t, int w)
{
edge[kNum].f = f;
edge[kNum].t = t;
edge[kNum].w = w;
edge[kNum].next = head[f];
head[f] = kNum ++;
}
int find(int x){
int l = 0, r = ans - 1;
while( l < r ){
int mid = ( l + r ) >> 1;
if( dp[mid] < x )
l = mid + 1;
else if( dp[mid] == x )
return mid;
else
r = mid;
}
return l;
}
void solve(){
for(int i = 0; i < N; i ++){
scanf("%d",&num[i]);
}
dp[0] = num[0];
ans = 1;
for(int i = 1; i < N; i ++){
if( num[i] > dp[ans-1] ){
dp[ans] = num[i];
ans ++;
}
else{
int d = find(num[i]);
dp[d] = num[i];
}
}
printf("%d\n",ans);
}
int main()
{
// freopen("d:\\test.txt", "r", stdin);
while(cin>>N){
solve();
}
return 0;
}