hdu 3605(二分图多重匹配)
Escape
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 8747 Accepted Submission(s): 2026
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.
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
If you can output YES, otherwise output NO.
1
1
2 2
1 0
1 0
1 1
NO
#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(二分图多重匹配)的更多相关文章
- HDU 1669 二分图多重匹配+二分
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- hdu 1669(二分图多重匹配)
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- HDU 3609 二分图多重匹配
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU - 3605 Escape (缩点+最大流/二分图多重匹配)
题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...
- HDU 3605 Escape(二分图多重匹配问题)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU3605 Escape —— 二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
- 【POJ 1698】Alice's Chance(二分图多重匹配)
http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...
随机推荐
- PHP检测json格式数据
首先要记住json_encode返回的是字符串, 而json_decode返回的是对象 判断数据不是JSON格式: 复制代码代码如下: function is_not_json($str){ ...
- 【DP】【Uva437】UVA437 The Tower of Babylon
传送门 Description Input Output Sample Input Sample Output Case : maximum height = Case : maximum heigh ...
- 史上最全Linux提权后获取敏感信息方法
http://www.freebuf.com/articles/system/23993.html 在本文开始之前,我想指出我不是专家.据我所知,在这个庞大的区域,没有一个“神奇”的答案.分享,共享( ...
- 读取proc/uptime信息。
#include <stdio.h> #include<unistd.h> #include<sys/types.h> #include<sys/stat.h ...
- HDU 4549 矩阵快速幂+快速幂+欧拉函数
M斐波那契数列 Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others)Total Sub ...
- Spring Boot 启动报错 Exception in thread "main" java.lang.StringIndexOutOfBoundsException: String index out of range: 37
使用命令 java -jar springBoot.jar 启动项目,结果报错如下: Exception at java.lang.String.substring(String.java:) at ...
- ZooKeeper食谱(八)
使用ZooKeeper构造高级别应用的指南 在这个文章中,你将会发现使用ZooKeeper来实现高级别功能的指南.所有的它们在客户端上被实现而不需要ZooKeeper特别的支持.希望社区将注意到这些约 ...
- LightOJ 1306 - Solutions to an Equation 裸EXGCD
本题是极其裸的EXGCD AX+BY+C=0 给你a b c 和x与y的区间范围,问你整数解有几组 作为EXGCD入门,题目比较简单 主要需要考虑区间范围的向上.向下取整,及正负符号的问题 问题是这正 ...
- Robot Framework 常用关键字使用方法
1. Select From Listid=sourceConnoracle_source 从下拉框选取值. 2. Select Radio button name value 选择单选框.也可以点 ...
- 【游记】GDOI 2017
Day 0 学校好大>_<! 酒店好高级>_<! 晚上复习代码的时候很困QAQ,中间和hwh面基.复习到SA的时候因为太久没看忘记板子的意思了又背不下来,于是不看了,相信考了也 ...