?? gets an sequence S with n intergers(0 < n <= 100000,0<= S[i] <= 1000000).?? has a magic so that he can change 0 to any interger(He does not need to change all 0 to the same interger).?? wants you to help him to find out the length of the longest increasing (strictly) subsequence he can get.
For each case,the first line contains an interger n,which is the length of the array s.
The next line contains n intergers separated by a single space, denote each number in S.
2 7 2 0 2 1 2 0 5 6 1 2 3 3 0 0
Case #1: 5
Case #2: 5
In the first case,you can change the second 0 to 3.So the longest increasing subsequence is 0 1 2 3 5.注意这道题0可以变成任何数包括负数
/*
0可以转化成任意整数,包括负数,
然求LIS时尽量把0都放进去必定是正确的。
因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,
统计结果的时候再算上0的数量。为了保证严格递增,
我们可以将每个权值S[i]减去i前面0的个数,再做LIS,
就能保证结果是严格递增的。
*/
#include <cstdio>
#include <algorithm>
#define INF 0x3f3f3f3f
#define maxx 100000+10
using namespace std;
int dp[maxx],a[maxx],t[maxx];
int main()
{
int n,i,j,k,num;
int T;
int Case=0;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
num=0,k=0;
for(i=0;i<n;i++)
{
dp[i]=INF;
scanf("%d",&a[i]);
}
for(i=0;i<n;i++)
{
if(a[i]==0)
{
num++;
continue;
}
a[i]-=num;
a[k++]=a[i];
}
for(i=0;i<k;i++)
*lower_bound(dp,dp+n,a[i])=a[i];
printf("Case #%d: %d\n",++Case,lower_bound(dp,dp+k,INF)-dp+num);
}
return 0;
}
/*
1 8 1 3 4 0 2 5 4 7
*/