Escape

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

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 个人,m颗行星, 每个人可以适应其中的某一些星球,每个星球有一个容量上限,问着n个人能否全部安排到这m个行星?
题解:n 个人和行星是一对多的关系,所以我们对每个人和其移居行星建边,然后进行二分图多重匹配即可。
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;
const int N = ;
const int M = ;
int graph[N][M];
int cap[M];
int n,m;
int linker[M][N],link[N];
bool vis[M];
bool dfs(int u){
for(int v=;v<=m;v++){
if(!vis[v]&&graph[u][v]){
vis[v] = true;
if(link[v]<cap[v]){
linker[v][link[v]++] = u;
return true;
}
for(int i=;i<link[v];i++){
if(dfs(linker[v][i])){
linker[v][i] = u;
return true;
}
}
}
}
return false;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF){
int x;
memset(graph,,sizeof(graph));
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
scanf("%d",&x);
if(x) graph[i][j] = ;
}
}
for(int i=;i<=m;i++) scanf("%d",&cap[i]);
memset(link,,sizeof(link));
bool flag = true;
for(int i=;i<=n;i++){
memset(vis,false,sizeof(vis));
if(!dfs(i)){ ///第i个人不行就直接结束
flag = false;
break;
}
}
if(flag) printf("YES\n");
else printf("NO\n");
}
return ;
}

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

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

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

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

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

  3. HDU 3609 二分图多重匹配

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

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

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

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

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

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

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

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

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

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

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

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

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

随机推荐

  1. float,absolute脱离文档流的总结

    dom元素脱离文档流,有如下几种方式: 1. float 脱离文档流,其他dom元素无视他,在其下方布局,但是其未脱离文本流,其他元素的文本会认为他存在,环绕他布局.父元素会无视他,因此无法获取其高度 ...

  2. bzoj4300: 绝世好题(DP)

    按位DP f[i]表示第i位为1的最长子序列 #include<iostream> #include<cstring> #include<cstdlib> #inc ...

  3. [IOI2007]Miners 矿工配餐

    link 其实就是一个比较简单的$IOI$题.简单$dp$就行,设$5$维$dp$即可 最后在滚动一下,判一下可行性即可. #include<iostream> #include<c ...

  4. CSS的历史与工作原理

    1. 浏览器的发展与CSS 网页浏览器主要通过HTTP协议连接网页服务器而取得网页,HTTP容许网页浏览器送交资料到网页服务器并且获取网页.目前最常用的 HTTP 是 HTTP/1.1,这个协议在RF ...

  5. ACE中TCP通信

    转载于:http://www.cnblogs.com/TianFang/archive/2006/12/07/585095.html 概述: 传输控制协议TCP(Transmission Contro ...

  6. mysql的时间函数整理

      转:这里总结的非常齐全: http://fengbin2005.iteye.com/blog/1999763   Mysql时间函数 对于每个类型拥有的值范围以及并且指定日期何时间值的有效格式的描 ...

  7. HDU 5533Dancing Stars on Me 基础几何

    Problem Description The sky was brushed clean by the wind and the stars were cold in a black sky. Wh ...

  8. WebDriver中如何处理Iframe 及 嵌套Iframe

    最近在用webdriver进行爬虫的时候,遇到了网站存在iframe的情况,处理了好久没有解决,后来发现原来webdriver自带处理方法,汗颜.. 1.iFrame有ID 或者 name的情况 // ...

  9. Freemarker的配置与使用

    1.在pro.xml配置文件中引入架包 <!--freemarker-->  <dependency>   <groupId>freemarker</grou ...

  10. mysql数据库cmd直接登录

    找到mysql的安装路径: 将该路径配置到环境变量中: win+R代开dos窗口:输入mysql -uroot -p回车,输入密码.