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 ...
随机推荐
- 【DP】【P2734】游戏 A Game
传送门 Description 有如下一个双人游戏:N个正整数的序列放在一个游戏平台上,游戏由玩家1开始,两人轮流从序列的任意一端取一个数,取数后该数字被去掉并累加到本玩家的得分中,当数取尽时,游戏结 ...
- POJ1236:Network of Schools (思维+Tarjan缩点)
Network of Schools Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24880 Accepted: 99 ...
- 查看Django版本
python -m django --version dd
- 通过psexec实现远程安装软件包
1.在管理机上下载和安装psexec https://docs.microsoft.com/en-us/sysinternals/downloads/psexec 2.在管理机上编写bat脚本,存放在 ...
- ZooKeeper管理员指南(九)
部署 这部分包含了部署ZooKeeper的信息和覆盖这些话题 系统要求 集群(多服务)安装 单服务和开发者安装 前两部分假定你对在例如数据中心的生产环境安装ZooKeeper有兴趣.最后一部分包含你在 ...
- linux查找进程id端口占用和杀死进程
linux 查找进程id端口占用和杀死进程 ps 命令用于查看当前正在运行的进程 辅助上grep 用于搜索匹配ps -ef | grep java ps ax : 显示当前系统进程的列表 ps aux ...
- 洛谷 P1722 矩阵 II
题目背景 usqwedf 改编系列题. 题目描述 如果你在百忙之中抽空看题,请自动跳到第六行. 众所周知,在中国古代算筹中,红为正,黑为负…… 给定一个1*(2n)的矩阵(usqwedf:这不是一个2 ...
- 51Nod 1305 Pairwise Sum and Divide | 思维 数学
Output 输出fun(A)的计算结果. Input示例 3 1 4 1 Output示例 4 first try: #include "bits/stdc++.h" using ...
- Html5 面试题汇总
1.HTML5 为什么只需要写 <!DOCTYPE HTML>? 答案解析: Html5不基于SGML,因此不需要对DTD进行引用,但是需要DOCTYPE来规范浏览器的行为(让浏览器按照他 ...
- 策略模式 C#
策略模式定义了一系列的算法,并将每一个算法封装起来,而且使它们还可以相互替换.策略模式让算法独立于使用它的客户而独立变化. 抽象策略角色: 策略类,通常由一个接口或者抽象类实现. 具体策略角色:包装了 ...