"bzoj1109" [POI2007] Stacked wood klo

Source: Internet
Author: User
Description

Mary has some bricks in her birthday present. The bricks are all cubes of the same size. Each block has a number above it. Mary is using his
All the bricks have a high tower on the base. Mom told Mary that the purpose of the game was to build a tower so that the most bricks were in the right place. One of the above is written with a number I
The correct position of the building blocks is the tower from the bottom to the top of the number I position. Mary decided to remove some of the existing towers so that the most bricks were in the right
The location. Please tell Mary which bricks she should remove. Input

The first behavior is a number n, which indicates the initial height of the tower. The second line contains n number a1,a2,..., An, which represents the number of blocks above each block.
(1<=n<=100000,1<=ai<=1000000). Output

Note: Please output how many points can be in the correct location Sample Input 5
1 1 2 5 4 Sample Output 3 HINT


Solve

DP, after the introduction of the equation found that the answer is to find two-dimensional partial order, to order, another dimension with a tree-like array maintenance

#include <algorithm>
#include <iostream>
#include <cstdio>
#define LOWBIT (x) (x& ( -X))
using namespace std;
const int n=100005;
const int m=1000005;
int Sum[m],ss,n,f[n],ans;
struct node{
    int a1,a2;
    friend bool Operator < (node I,node j) {
        return (I.A1==J.A1)? ( I.A2<J.A2):(i.a1>j.a1);
    }
} A[n];
inline void Add (int i,int key) {for
    (; i<=m;i+=lowbit (i))
        Sum[i]=max (Sum[i],key);
}
inline int query (int i) {for
    (ss=0;i;i-=lowbit (i))
        Ss=max (Ss,sum[i]);
    return SS;
}
int main () {
    scanf ("%d", &n);
    for (int i=1;i<=n;++i) {
        scanf ("%d", &a[i].a2);
        a[i].a1=a[i].a2-i;
    }
    Sort (a+1,a+n+1);
    for (int i=1;i<=n;++i) {
        if (a[i].a1>0) continue;
        F[i]=query (a[i].a2-1) +1;
        Add (A[i].a2,f[i]);
        Ans=max (Ans,f[i]);
    }
    printf ("%d", ans);
    return 0;
}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.