bzoj2034: [2009国家集训队]最大收益

本校唯一国家队爷出的题。。。真流弊

强行卡掉优化构图

大家一起去%吧

我觉得离散化以后就是一个类似匈牙利的贪心了。。。

#include<cstdio>
#include<iostream>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<cmath>
using namespace std;
typedef long long LL;

struct node{int l,r,d;}a[5100];
bool cmpl(node n1,node n2){return n1.l<n2.l;}
bool cmpd(node n1,node n2){return n1.d>n2.d;}
int pos[5100],match[5100];
bool gofind(int k,int x)
{
    if(a[k].r<pos[x])return false;
    if(match[x]==0)
        {match[x]=k;return true;}
    else
    {
        if(a[match[x]].r<a[k].r)return gofind(k,x+1);
        else if(gofind(match[x],x+1))
            {match[x]=k;return true;}
        return false;
    }
}
int main()
{
    freopen("a.in","r",stdin);
    freopen("a.out","w",stdout);
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d%d%d",&a[i].l,&a[i].r,&a[i].d);
        
    sort(a+1,a+n+1,cmpl);
    for(int i=1;i<=n;i++)pos[i]=max(pos[i-1]+1,a[i].l);
    for(int i=1,j=1;i<=n;i++)
    {
        while(pos[j]<a[i].l&&j<n)j++;
        a[i].l=j;
    }
    
    sort(a+1,a+n+1,cmpd);
    LL ans=0;
    for(int i=1;i<=n;i++)
        if(gofind(i,a[i].l))ans+=a[i].d;
    printf("%lld\n",ans);
    
    return 0;
}

 

转载于:https://www.cnblogs.com/AKCqhzdy/p/10245457.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值