题目地址:点击打开链接
思路:LIS水题
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
using namespace std;
int const maxn = 40000;
int a[maxn],stack1[maxn];
int main()
{
int t,n,i;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(i=0; i<n; i++)
{
scanf("%d",&a[i]);
}
int top = 0;
stack1[0] = 0;
for(i=0; i<n; i++)
{
if(a[i] > stack1[top])
{
stack1[++top] = a[i];
}
else
{
int left = 1,right = top,mid;
while(left <= right)
{
mid = (left + right) / 2;
if(a[i] > stack1[mid])
{
left = mid + 1;
}
else
{
right = mid - 1;
}
}
stack1[left] = a[i];
}
}
printf("%d\n",top);
}
return 0;
}