Escape

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

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
 
AC代码
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(a) (a).begin(), (a).end()
#define fillchar(a, x) memset(a, x, sizeof(a))
#define huan printf("\n")
#define debug(a,b) cout<<a<<" "<<b<<" "<<endl
#define ffread(a) fastIO::read(a)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN = 1e5+;//左集合大小
const int MAXM = ;//右集合大小
int uN,vN;//左右集合的数量
int g[MAXN][MAXM];
int linker[MAXM][MAXN];
bool used[MAXM];
int num[MAXM];//右集合的限制
bool dfs(int u)
{
for(int v = ; v < vN; v++)
if(g[u][v] && !used[v])
{
used[v] = true;
if(linker[v][] < num[v])
{
linker[v][++linker[v][]] = u;
return true;
}
for(int i = ; i <= num[v]; i++)
if(dfs(linker[v][i]))
{
linker[v][i] = u;
return true;
}
}
return false;
}
int hungary()
{
int res = ,flag=;
for(int i = ; i < vN; i++)
linker[i][] = ;
for(int u = ; u < uN; u++)
{
memset(used,false,sizeof(used));
if(dfs(u))
res++;
else //当前人不能匹配 直接就是NO了
{
flag=;
break;
}
}
return flag;
}
int main()
{
while(scanf("%d%d",&uN,&vN)!=EOF)
{
for(int i=;i<uN;i++)
for(int j=;j<vN;j++)
scanf("%d",&g[i][j]);
for(int i=;i<vN;i++)
scanf("%d",&num[i]);
if(hungary())
puts("NO");
else
puts("YES");
}
}
 

HDU 3609 二分图多重匹配的更多相关文章

  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 - 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. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

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

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

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

  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. 在colab上运行style-transfer

    1,  打开chrome浏览器,输入以下网址,打开风格转换主文件 https://colab.research.google.com/github/Hvass-Labs/TensorFlow-Tuto ...

  2. 通过HA方式操作HDFS

    之前操作hdfs的时候,都是固定namenode的地址,然后去操作.这个时候就必须判断namenode的状态为active还是standby,比较繁琐,如果集群使用了HA的形式,就很方便了 直接上代码 ...

  3. Tomcat和搜索引擎网络爬虫的攻防

    不知道广大程序员朋友们注意到一个现象么?使用百度是无法搜索到淘宝网的网页.为什么会造成这种现象?这就要从网络爬虫说起了. 咱们程序员假如自己搭设个人网站,在上面分享少量自己的技术文章,面临的一个重要问 ...

  4. Eclipse添加默认的JRE

    打开eclipse,依次点击如下选项Window->Preferences-> Java -> Installed JREs.步骤见下图.   选中Installed JREs选项出 ...

  5. leetcode_1039. Minimum Score Triangulation of Polygon_动态规划

    https://leetcode.com/problems/minimum-score-triangulation-of-polygon/ 题意:给定一个凸的N边形(N<=50),每个顶点有一个 ...

  6. 7-Java-C(搭积木)

    题目描述: 小明最近喜欢搭数字积木, 一共有10块积木,每个积木上有一个数字,0~9. 搭积木规则: 每个积木放到其它两个积木的上面,并且一定比下面的两个积木数字小. 最后搭成4层的金字塔形,必须用完 ...

  7. iview modal 弹框 模板

    iview modal 弹框 模板 <!-- * @description 上传图片 * @fileName camera.vue * @author 彭成刚 * @date // :: * @ ...

  8. python基础一day3 字符串

    对字符串进行的任何操作都是形成新的字符串. 切片顾头不顾尾 倒着取: 因为顾头不顾尾,所以4要取到 当步长省略时,可以同时省略最后一个冒号 写0时,取不到,什么都不写,可以取到 倒着取出全部的值,两种 ...

  9. Asp.Net Core 入门(三) —— 自定义中间件

    上一篇我们讲了Startup文件,其中着重介绍了中间件,现在我们就来自定义我们自己的中间件吧. 中间件通常封装在一个类中,并使用扩展方法进行暴露.它需要拥有一个类型为RequestDelegate的成 ...

  10. python-opencv遍历图片像素,并对像素进行操作

    看代码: def access_pixels(frame): print(frame.shape) #shape内包含三个元素:按顺序为高.宽.通道数 height = frame.shape[0] ...