HDU3605 Escape —— 二分图多重匹配
题目链接: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): 10349 Accepted Submission(s): 2476
in these planets.
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 <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
#define ms(a,b) memset((a),(b),sizeof((a)))
//#define LOCAL
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int maxn = 1e5+; int n, m;
int linker[][maxn];
int g[maxn][];
bool used[];
int num[]; bool dfs(int u)
{
for(int v = ; v<=m; 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;
} bool hungary()
{
for(int v = ; v<=m; v++)
linker[v][] = ;
for(int u = ; u<=n; u++)
{
memset(used,,sizeof(used));
if(!dfs(u)) return false; //如果这个人匹配不到,则直接退出。否则会超时。
}
return true;
} int main()
{
#ifdef LOCAL
freopen("", "r", stdin);
// freopen("output.txt", "w", stdout);
#endif while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i = ; i<=n; i++)
for(int j = ; j<=m; j++)
scanf("%d",&g[i][j]);
for(int i = ; i<=m; i++)
scanf("%d",&num[i]); if(hungary()) puts("YES");
else puts("NO");
}
}
HDU3605 Escape —— 二分图多重匹配的更多相关文章
- hdu3605 Escape 二分图多重匹配/最大流
2012 If this is the end of the world how to do? I do not know how. But now scientists have found tha ...
- HDU 3605 Escape(二分图多重匹配问题)
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 Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
- 【POJ 1698】Alice's Chance(二分图多重匹配)
http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...
- 稳定的奶牛分配 && 二分图多重匹配+二分答案
题意: 农夫约翰有N(1<=N<=1000)只奶牛,每只奶牛住在B(1<=B<=20)个奶牛棚中的一个.当然,奶牛棚的容量有限.有些奶牛对它现在住的奶牛棚很满意,有些就不太满意 ...
- hiho 第117周 二分图多重匹配,网络流解决
描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小Ho作为班上的班干部,统计分配比赛选手的重任也自然交到了他们手上. 已知小Hi和小Ho所在的班级一共有N名学生(包含 ...
- 【网络流24题】No.7 试题库问题 (最大流,二分图多重匹配)
[题意] 假设一个试题库中有 n 道试题. 每道试题都标明了所属类别. 同一道题可能有多个类别属性.现要从题库中抽取 m 道题组成试卷.并要求试卷包含指定类型的试题. 试设计一个满足要求的组卷算法. ...
随机推荐
- Flex 布局教程学习
转载自:阮一峰的网络日志(http://www.ruanyifeng.com/blog/2015/07/flex-grammar.html) 网页布局(layout)是 CSS 的一个重点应用. 布局 ...
- Markdown的css样式源码
http://www.cnblogs.com/zhangjk1993/p/5442676.html https://github.com/zhangjikai/markdown-css https:/ ...
- SQLServer 跟踪 扩展事件(Extended Events) 专家
http://blog.csdn.net/kk185800961/article/details/49725903
- 用Redis存储Tomcat集群的Session(转载)
本文转自http://blog.csdn.net/chszs/article/details/42610365 感谢作者 前段时间,我花了不少时间来寻求一种方法,把新开发的代码推送到到生产系统中部署, ...
- redis容量预估
2.存储的数据内容:前端系统登录用到的Token,类型:key:string(32),value:string(32)3.业务场景存数据:用户登录验证成功后,ICORE-PAP后台产生Token(st ...
- 【hibernate postgresql】注解@TypeDef/@Enumerated/数据库字段gender为枚举类型,从前台接受到实体后进行保存报错:org.postgresql.util.PSQLException: ERROR: column "gender" is of type gender but expression is of type character varying
数据库字段gender为枚举类型,从前台接受到实体后进行保存报错:org.postgresql.util.PSQLException: ERROR: column "gender" ...
- 前端模板inspinia
前端模板,可以下个免费的,可以花点小钱买.或者github搜索一个 https://chuibility.github.io/inspinia/ http://cn.inspinia.cn/layou ...
- 第五讲_图像识别之图像检测Image Detection
第五讲_图像识别之图像检测Image Detection 目录 物体检测 ILSVRC竞赛200类(每个图片多个标签):输出类别+Bounding Box(x,y,w,h) PASCAL VOC 20 ...
- HashMap 和 Hashtable 的同和不同
综述 可以直接根据 hashcode 值判断两个对象是否相等吗?肯定是不可以的,因为不同的对象可能会生成相同的 hashcode 值.虽然不能根据 hashcode 值判断两个对象是否相等,但是可以直 ...
- python(37)- 软件开发规范
软件开发规范 一.为什么要设计好目录结构? 1.可读性高: 不熟悉这个项目的代码的人,一眼就能看懂目录结构,知道程序启动脚本是哪个,测试目录在哪儿,配置文件在哪儿等等.从而非常快速的了解这个项目. 2 ...