题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1950
题意:LIS nlogn算法
代码:
#include <iostream>
#include <stdio.h>
#include <string>
#include <string.h>
#include <cmath>
#include <queue>
#include <vector>
#include <map>
#include <set>
using namespace std;
int ans[40010];
int a[40010];
int n;
int main()
{
int T;
scanf("%d",&T);
while (T--)
{
memset(a,0,sizeof(a));
memset(ans,0,sizeof(ans));
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&a[i]);
ans [1] = a[1];
int len = 1;
for(int i=2;i<=n;i++)
{
if (a[i] > ans[len])
ans[++len] = a[i];
else
{
int left = 1,right = len;
while (left <= right)
{
int mid = (left + right)/2;
if (a[i] >= ans[mid]) left = mid + 1;
else right = mid - 1;
}
ans [left] = a[i];
}
}
printf("%d\n",len);
}
return 0;
}