• 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
    ",ans);
        return 0;
    }
  • 相关阅读:
    Codeforces 1009F Dominant Indices
    UOJ #35 后缀排序 哈希做法
    bzoj 3670 [Noi2014]动物园
    动态规划 笔记

    常用模块和面向对象 类
    常用模块
    包的使用和常用模块
    日志
    复习列表,模块
  • 原文地址:https://www.cnblogs.com/nbwzyzngyl/p/8386921.html
Copyright © 2020-2023  润新知