题目链接:hdu1257
转化为单调递增最长子序列问题
#include <iostream>
#include <queue>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <string>
#include <map>
using namespace std;
const int inf = 0x3f3f3f3f;
const int N = 5005;
int d[N];
int a[N];
int main()
{
int T,n,i,j;
while(~scanf("%d",&n))
{
for(i = 0; i < n; i ++)
scanf("%d",&a[i]);
int top = 0;
d[0] = -inf;
for(i = 0; i < n; i ++){
if(a[i] > d[top]){
d[++top] = a[i];
continue;
}
int pos = lower_bound(d, d+top+1, a[i]) - d;
d[pos] = a[i];
}
printf("%d\n",top);
}
return 0;
}