二分+dp求最长下降子序列
#include<map>
#include<queue>
#include<cmath>
#include<cstdio>
#include<stack>
#include<iostream>
#include<cstring>
#include<algorithm>
#define LL int
#define inf 0x3f3f3f3f
#define eps 1e-8
#include<vector>
#define ls l,mid,rt<<1
#define rs mid+1,r,rt<<1|1
using namespace std;
int arr[100010],top,dp[10010];
int so(int x){
int l=1,r=top;
while(r>=l){
int mid=(l+r)/2;
if(dp[mid]==x)
return mid;
if(dp[mid]<x)
l=mid+1;
else r= mid-1;
}
return l;
}
int main(){
int n,m,i,j,k;
int cla;
scanf("%d",&cla);
while(cla--){
memset(dp,0,sizeof(dp));
scanf("%d",&n);
for(i = n-1;i >= 0 ;-- i)
scanf("%d",&arr[i]);
top = 1;
dp[1]= arr[0];
for(i = 1;i < n;++ i){
int tmp=so(arr[i]);
dp[tmp] = arr[i];
if(tmp>top)
top=tmp;
}
printf("%d\n",top);
}
return 0;
}