【codevs 3995】最长严格上升子序列(加强版)

模板题
nlog(n)

#include 
#include 
#include 
#include 
using namespace std;
const int MAXN = 1000000 + 5;
int g[MAXN],len,n,a[MAXN];
int find(int x)
{
    int l = 0,r = n;
    int mid = (l + r) / 2;
    while(l <= r)
    {
        if(g[mid] < x)
            l = mid + 1;
        else if(g[mid] > x)
            r = mid - 1;
        else
            return mid;
        mid = (l + r) / 2;
    }
    return l;
}
void dpdpd()
{
    len = 1;
    memset(g,0x3f,sizeof(g));
    g[0] = -1;
    g[1] = a[1];
    for(int i = 2;i <= n;i ++)
    {
        int j = find(a[i]);    
        g[j] = min(g[j],a[i]);
        len = max(len,j);
    }
    return;
}
int main()
{
    scanf("%d",&n);
    for(int i = 1;i <= n;i ++)
        scanf("%d",&a[i]);
    dpdpd();
    printf("%d\n",len);
    return 0;
}

你可能感兴趣的:(=====动态规划=====,序列型)