[POI2008] PLA-Postering

给你 (n) 个相连的矩形建筑,让你用最少海报把他们覆盖掉,海报不能重叠,也不可以高出被覆盖的矩形。

1582190893645

Solution

考虑维护一个单调递增的栈,每次插入时弹掉所有比自己高的,如果自己和末端一样高就不贡献,否则贡献。

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

const int N = 1000005;
int b[N],a[N],n,q[N],top;

signed main() {
    ios::sync_with_stdio(false);
    cin>>n;
    for(int i=1;i<=n;i++) {
        cin>>b[i]>>a[i];
    }
    int ans=0;
    for(int i=1;i<=n;i++) {
        while(top && q[top]>a[i]) --top;
        if(q[top]<a[i]) {
            q[++top]=a[i];
            ++ans;
        }
    }
    cout<<ans;
}

原文地址:https://www.cnblogs.com/mollnn/p/12336638.html