BZOJ 4276: [ONTAK2015]Bajtman i Okrągły Robin

最大权值匹配,贪心匈牙利即可。

检查一些人是否能被全部抓住可以采用左端点排序,右端点优先队列处理。

By:大奕哥

#include<bits/stdc++.h>
using namespace std;
const int N=5005;
struct node{
    int l,r,c;
    bool operator <(const node &b)const{
        return c>b.c;
    }
}p[N];
int match[N],ans,n;
bool v[N];
bool Hungary(int x)
{
    for(int i=p[x].l;i<=p[x].r;++i)
    {
        if(!v[i])
        {
            v[i]=1;
            if(!match[i]||Hungary(match[i]))
            {
                match[i]=x;
                return 1;
            }
        }
    }
    return 0;
}
int main()
{
//    freopen("1.out","r",stdin);
//    freopen("my.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;++i)
    {
        scanf("%d%d%d",&p[i].l,&p[i].r,&p[i].c);
        p[i].r--;
    }
    sort(p+1,p+1+n);
    for(int i=1;i<=n;++i)
    {
        memset(v,0,sizeof(v));
        if(Hungary(i))ans+=p[i].c;
    }
    printf("%d\n",ans);
    return 0;
}

 

posted @ 2018-01-30 19:37  大奕哥&VANE  阅读(191)  评论(0编辑  收藏  举报