首页 > 其他 > 详细

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

时间:2019-01-09 17:12:33      阅读:208      评论:0      收藏:0      [点我收藏+]

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

强行卡掉优化构图

大家一起去%吧

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

#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;
}

 

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

原文:https://www.cnblogs.com/AKCqhzdy/p/10245457.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!