BZOJ2298:[HAOI2011]problem a(DP)

题面

每句话等价于:
①排名属于[a+1,n-b]的人分数相等。
②那个人排名属于[a+1,n-b]。

原题变成了序列上选若干条不相交的线段,使得权值最大。
且每条线段的权值不能超过其长度。

#include <iostream>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;
#define mmst(a, b) memset(a, b, sizeof(a))
#define mmcp(a, b) memcpy(a, b, sizeof(b))

typedef long long LL;

const int N=100100;

struct yy
{
    int l,r,val;
}f[N];

bool cmp(yy x,yy y)
{
    if(x.r==y.r)
    return x.l<y.l;
    return x.r<y.r;
}

int n,dp[N];

int main()
{
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d%d",&f[i].l,&f[i].r);
        f[i].l++;
        f[i].r=n-f[i].r;
        f[i].val=1;
    }

    sort(f+1,f+n+1,cmp);

    for(int i=2;i<=n;i++)
    if(f[i].l==f[i-1].l&&f[i].r==f[i-1].r)
    {
        f[i].val+=f[i-1].val;
        f[i-1].val=0;
    }

    int hh=1;
    for(int i=1;i<=n;i++)
    {
        dp[i]=dp[i-1];
        while(f[hh].r<i)
        hh++;

        while(f[hh].r==i&&hh<=n)
        {
            if(f[hh].val&&f[hh].l<=i)
            dp[i]=max(dp[i],dp[f[hh].l-1]+min(f[hh].val,i-f[hh].l+1));
            hh++;
        }
    }
    cout<<n-dp[n]<<endl;

    return 0;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值