链接:http://acm.hdu.edu.cn/showproblem.php?pid=5748
题意:对每一位的最长上升子序列,求出另一个序列。
例如:12435。
对第一位:1
对第二位:12
对第三位:124
对第四位:124
对第五位:1245
所以结果就是:12334。
所以对每一位都求一下最长上升子序列就好啦。
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
const int MAXN=100005;
const int INF=0x3f3f3f3f;
long long a[MAXN];
long long dp[MAXN];
using namespace std;
int main (void)
{
int t;
cin>>t;
while(t--)
{
int num;
scanf("%d",&num);
memset(dp,0x3f,sizeof(dp));
for(int i=0;i<num;i++)
{
scanf("%lld",&a[i]);
// dp[i]=INF;
*lower_bound(dp,dp+num,a[i])=a[i];
long long le=lower_bound(dp,dp+num,a[i])-dp;
printf("%lld%s",le+1,i==num-1?"\n":" ");
}
}
return 0;
}