HUD 5773 LIS(最长上升序列)

***关于lower_bound()的用法参见:http://blog.csdn.net/niushuai666/article/details/6734403

lower_bound用法:函数lower_bound()在first和last中的前闭后开的区间进行二分查找,返回大于或等于val的第一元素的位置(位置是从零开始的)。如果所有元素都小于val,则返回last的位置。***

#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<cctype>
#include<queue>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long LL;
#define N 101000
#define INF 0x3f3f3f

int a[N], g[N], d[N];

int main()
{
    int T, n, cas=1;
    scanf("%d", &T);

    while(T--)
    {
        scanf("%d", &n);
        for(int i=1; i<=n; i++)
        {
            g[i]=INF;
            scanf("%d", &a[i]);
        }

        int num, ans;
        num=ans=0;

        for(int i=1; i<=n; i++)
        {
            if(a[i]==0)
            {
                num++;
                continue;
            }
            a[i]-=num;//减去这个数前面零的个数,这样可以剔点一些数,为零的变换留有足够大的空间
            int k=lower_bound(g+1, g+n+1, a[i])-g;
            d[i]=k;
            g[k]=a[i];
            ans=max(ans, d[i]);
        }
        printf("Case #%d: %d
", cas++, ans+num);
    }
    return 0;
}
原文地址:https://www.cnblogs.com/9968jie/p/5718967.html