[POI 2007] 堆积木

[题目链接]

          https://www.lydsy.com/JudgeOnline/problem.php?id=1109

[算法]

          DP

[代码]

          

#include<bits/stdc++.h>
using namespace std;
#define MAXN 100010

struct info
{
        int x,y;
} b[MAXN];

int i,n,m,cnt,pos;
int a[MAXN],q[MAXN];

inline bool cmp(info a,info b)
{
        return a.x == b.x ? a.y < b.y : a.x < b.x;
}

int main() 
{
        
        scanf("%d",&n);
        for (i = 1; i <= n; i++) 
        {
                scanf("%d",&a[i]);
                if (i - a[i] < 0) continue;
                b[++m].x = i - a[i];
                b[m].y = a[i];
        }
        sort(b+1,b+m+1,cmp);
        for (i = 1; i <= m; i++)
        {
                if (i == 1 || b[i].y > q[cnt]) q[++cnt] = b[i].y;
                else
                {
                        pos = lower_bound(q+1,q+cnt+1,b[i].y) - q;
                        q[pos] = b[i].y;
                }         
        }
        
        printf("%d
",cnt);
        
        return 0;
    
}
原文地址:https://www.cnblogs.com/evenbao/p/9353192.html