zoukankan      html  css  js  c++  java
  • HDU(3605),二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605

    Escape

    Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
    Total Submission(s): 8944    Accepted Submission(s): 2084


    Problem Description
    2012 If this is the end of the world how to do? I do not know how. But now scientists have found that some stars, who can live, but some people do not fit to live some of the planet. Now scientists want your help, is to determine what all of people can live in these planets.
     
    Input
    More set of test data, the beginning of each data is n (1 <= n <= 100000), m (1 <= m <= 10) n indicate there n people on the earth, m representatives m planet, planet and people labels are from 0. Here are n lines, each line represents a suitable living conditions of people, each row has m digits, the ith digits is 1, said that a person is fit to live in the ith-planet, or is 0 for this person is not suitable for living in the ith planet.
    The last line has m digits, the ith digit ai indicates the ith planet can contain ai people most..
    0 <= ai <= 100000
     
    Output
    Determine whether all people can live up to these stars
    If you can output YES, otherwise output NO.
     
    Sample Input
    1 1 1 1 2 2 1 0 1 0 1 1
     
    Sample Output
    YES NO
     
    Source
     
    题意:N(N<100,000)个人要去M(M<10)个星球,每个人只可以去一些星球,一个星球最多容纳Ki个人,输出是否所有人都可以选择自己的星球。
     
    此题数据绝对很水,我不小心把写成match[][15]这都能过,哈哈哈。
    多重匹配转换为最大匹配,把n个容量拆成n个点。
    #include <stdio.h>
    #include <string.h>
    
    int n,m;
    int maps[100010][15];
    int match[15][100010];
    int cnt[15];
    bool use[15];
    int cap[15];
    
    bool DFS(int u)
    {
        for(int i=0; i<m; i++)
        {
            if(!use[i]&&maps[u][i])
            {
                use[i] = true;
                if(cnt[i]<cap[i])
                {
                    match[i][cnt[i]++] = u;
                    return true;
                }
                else
                {
                    for(int j=0; j<cap[i]; j++)
                    {
                        if(DFS(match[i][j])==true)
                        {
                            match[i][j] = u;
                            return true;
                        }
                    }
                }
            }
        }
        return false;
    }
    
    int main()
    {
        while(~scanf("%d%d",&n,&m))
        {
            memset(match,-1,sizeof(match));
            memset(maps,0,sizeof(maps));
            memset(cap,0,sizeof(cap));
            memset(cnt,0,sizeof(cnt));
            for(int i=0; i<n; i++)
                for(int j=0; j<m; j++)
                    scanf("%d",&maps[i][j]);
            for(int i=0; i<m; i++)
                scanf("%d",&cap[i]);
    
            bool flag = true;
            for(int i=0; i<n; i++)
            {
                memset(use,false,sizeof(use));
                if(DFS(i)==false)
                {
                    flag = false;
                    break;
                }
            }
            if(flag) puts("YES");
            else puts("NO");
        }
        return 0;
    }
     
     
  • 相关阅读:
    用prototype属性来模拟一下类的继承
    Ajax 教程:Ajax 入门简介
    Ajax工作原理
    最新的Ajax教程和技术(上篇)
    javascript面向对象技术基础
    浏览器对象模型
    jQuery (选择器,属性,筛选,文档处理)
    shell(一)
    ntpntpdate时间同步
    centos7新系统安装
  • 原文地址:https://www.cnblogs.com/TreeDream/p/5763824.html
Copyright © 2011-2022 走看看