纯粹的LIS,参见 POJ 1836
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define maxN 1002
int findLen(short* x,int left,int right,short val)
{
int mid;
while(left <= right)
{
mid = (left+right)/2;
if(x[mid] == val)
return mid;
if(val > x[mid])
left = mid+1;
else
right = mid-1;
}
return left;
}
int main()
{
int i,N;
int maxL,tmpL;
short s[maxN];
short minRear[maxN];
while(~scanf("%d",&N))
{
for(i = 1;i <= N;i++)
scanf("%hd",s+i);
minRear[1] = s[1];
maxL = 1;
for(i = 2;i <= N;i++)
{
tmpL = findLen(minRear,1,maxL,s[i]);
minRear[tmpL] = s[i];
if(maxL < tmpL)
maxL = tmpL;
}
printf("%d\n",maxL);
}
return 0;
}