题目链接: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[][];
int match[][];
int cnt[];
bool use[];
int cap[]; bool DFS(int u)
{
for(int i=; 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=; 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,-,sizeof(match));
memset(maps,,sizeof(maps));
memset(cap,,sizeof(cap));
memset(cnt,,sizeof(cnt));
for(int i=; i<n; i++)
for(int j=; j<m; j++)
scanf("%d",&maps[i][j]);
for(int i=; i<m; i++)
scanf("%d",&cap[i]); bool flag = true;
for(int i=; i<n; i++)
{
memset(use,false,sizeof(use));
if(DFS(i)==false)
{
flag = false;
break;
}
}
if(flag) puts("YES");
else puts("NO");
}
return ;
}
 
 

HDU(3605),二分图多重匹配的更多相关文章

  1. hdu 3605(二分图多重匹配)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  2. HDU 1669 二分图多重匹配+二分

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  3. hdu 1669(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  4. HDU 3609 二分图多重匹配

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  5. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  6. HDU 3605 Escape(二分图多重匹配问题)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  7. HDU3605 Escape —— 二分图多重匹配

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others)    ...

  8. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

  9. hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)

    #1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...

  10. 【POJ 1698】Alice's Chance(二分图多重匹配)

    http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...

随机推荐

  1. JavaScript内的类型转换

    JavaScript内的类型转换 1.分为自动转换和强制转换,我们一般用强制转换.其他类型转换为整数是parseInt();其他类型转化为小数parseFloat(); 2.判断是不是一个合法数字   ...

  2. 字典:NSDictionary的应用举例

    字典就是关键字及其定义(描述)的集合.Cocoa中的实现字典的集合NSDictionary在给定的关键字(通常是一个NSString)下存储一个数值(可以是任何类型的对象).然后你就可以用这个关键字来 ...

  3. [转]Apache Maven 入门篇(下)

    原文地址: Apache Maven 入门篇(下) 作者:George Ma 第一篇文章大概的介绍了一下Apache Maven以及它的下载和安装,并且运行了一个简单的示例.那么在对maven有了一点 ...

  4. java 与 R 相互调用

    https://www.r-project.org/ http://cos.name/2013/08/r-rjava-java/ http://blog.csdn.net/hwssg/article/ ...

  5. RMQ(非log2储存方法)

    2016-03-31 RMQ 难度级别:B: 运行时间限制:1000ms: 运行空间限制:256000KB: 代码长度限制:2000000B 试题描述 长度为n的数列A,以及q个询问,每次询问一段区间 ...

  6. Ul li 竖排 菜单

    Ul li 竖排 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://ww ...

  7. 视频处理控件TVideoGrabber中如何混合多个视频源(2)

    在前面的<视频处理控件TVideoGrabber混合多个视频源(1)>一文中,已经对TVideoGrabber中混合视频源做了一些内容的说明,本文将继续前文: >>>TV ...

  8. struts2 笔记04 杂记

    流程: 1. StrutsPrepareAndExcuteFilter:StrutsPrepareAndExcuteFilter作为前端控制器,是整个Struts2的调度中心. 2. ActionMa ...

  9. 鸟哥的linux私房菜学习记录之档案与目录管理

    绝对路径和相对路径 绝对路径就是从根目录到某个目录下的路径,从根目录写起,也就是/ 相对路径就是从用户当前目录的路径写起 目录相关操作 cd 切换路径 例如:cd /var/www 切换到/var/w ...

  10. Java中main方面面试题

    1.不用main方法如何定义一个类? 不行,没有main方法我们不能运行Java类. 在Java 7之前,你可以通过使用静态初始化运行Java类.但是,从Java 7开始就行不通了. 2.main() ...