hdu_5773_The All-purpose Zero(LIS)

题目链接:hdu_5773_The All-purpose Zero

题意:

给你一串数,让你求LIS,不过这里的0可以改变为任意数

题解:

官方题解讲的很清楚

1010 The All-purpose Zero

0可以转化成任意整数,包括负数,显然求LIS时尽量把0都放进去必定是正确的。因此我们可以把0拿出来,对剩下的做O(nlogn)的LIS,统计结果的时候再算上0的数量。为了保证严格递增,我们可以将每个权值S[i]减去i前面0的个数,再做LIS,就能保证结果是严格递增的。

 1 #include<bits/stdc++.h>
 2 #define F(i,a,b) for(int i=a;i<=b;++i)
 3 using namespace std;
 4 
 5 const int N=1e5+7;
 6 int a[N],b[N];
 7 int main(){
 8     int t,n,tp,ic=1;
 9     scanf("%d",&t);
10     while(t--)
11     {
12         scanf("%d",&n);
13         int cnt=0,ed=0,len;
14         F(i,1,n)
15         {
16             scanf("%d",&tp);
17             if(tp)a[++ed]=tp-cnt;else cnt++;
18         }
19         if(!ed)printf("Case #%d: %d
",ic++,n);
20         else{
21             b[len=1]=a[1];
22             F(i,2,ed)if(a[i]>b[len])b[++len]=a[i];
23             else b[lower_bound(b+1,b+1+len,a[i])-b]=a[i];
24             printf("Case #%d: %d
",ic++,len+cnt);
25         }
26     }
27     return 0;
28 }
View Code
原文地址:https://www.cnblogs.com/bin-gege/p/5718547.html