hdu 3605 Escape 二分图的多重匹配(匈牙利算法)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605
Escape
what all of people can live in these planets.
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
1
1 2 2
1 0
1 0
1 1
YES
NO

假设Pi<Ki那么就直接上了,否则的话继续搜索Yi已经匹配的每个点并将Yi染色,由于Yi搜一次就须要染色了。并且Y方点最多是10个,所以每次找增广路的深度最多是10,这样就非常快了。!。(用c++交吧)
#include <iostream>
#include <cstdio>
#include <cstring> using namespace std; int n,m;
int w[15],cnt[15];
int Map[100010][12],mat[12][100010];
bool vis[15]; bool Find(int x)
{
for(int i=0;i<m;i++)
if(!vis[i]&&Map[x][i])
{
vis[i]=1;
if(cnt[i]<w[i])
{
mat[i][cnt[i]++]=x;
return true;
}
for(int j=0;j<cnt[i];j++)
if(Find(mat[i][j]))
{
mat[i][j]=x;
return true;
}
}
return false;
} bool ok()
{
memset(cnt,0,sizeof(cnt));
for(int i=0;i<n;i++)
{
memset(vis,0,sizeof(vis));
if(!Find(i))
return false;
}
return true;
} int main()
{
while(~scanf("%d%d",&n,&m))
{
for(int i=0;i<n;i++)
for(int j=0;j<m;j++)
scanf("%d",&Map[i][j]);
for(int i=0;i<m;i++)
scanf("%d",&w[i]);
if (ok()==1)
printf ("YES\n");
else
printf ("NO\n");
}
return 0;
}
hdu 3605 Escape 二分图的多重匹配(匈牙利算法)的更多相关文章
- HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))
Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Oth ...
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
- USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)
The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...
- HDU 3605 Escape (网络流,最大流,位运算压缩)
HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...
- Hdu 3605 Escape (最大流 + 缩点)
题目链接: Hdu 3605 Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...
- 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 ...
- HDU(3605),二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- hdu 2063 给男女匹配 (匈牙利算法)
来源:http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意: 有k个组合a,b组合,代表a愿意与b坐过山车,共m个女生 n个男生,问有多少个满意的匹配 题 ...
随机推荐
- css3新特性选择器(补充)
1.选择p标签中的第一个字符 p:first-letter{ color:red; font-size:25px; } 2.选择p标签中的第一行 p:first-line{ color:red; fo ...
- springboot扫描通用的依赖模块
将实际使用类的启动类改为如下形式启动: public class OrderApplication { public static void main(String[] args) { Object[ ...
- 【DRF路由】
在urls.py文件中按照如下步骤写,即可正确使用DRF的内置路由. from .views import BookModel # 1. 导入我们的视图 from rest_framework.rou ...
- Linux下关机命令的区别 (halt,poweroff,reboot,shutdown,init)
1.shutdown shutdown命令安全地将系统关机. 而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭.并且login指令会被冻结﹐即新的用户不能再登录 ...
- 【2017 Multi-University Training Contest - Team 3】RXD and math
[Link]: [Description] [Solution] 发现1010mod(109+7)=999999937; 猜测答案是nk 写个快速幂; 注意对底数先取模; [NumberOf WA] ...
- 【剑指Offer面试题】九度OJ1384:二维数组中的查找
下决心AC全部剑指offer面试题. 九度OJ面试题地址:http://ac.jobdu.com/hhtproblems.php 书籍:何海涛--<剑指Offer:名企面试官精讲典型编程题> ...
- Codeforces Round #195 (Div. 2) 少部分题解
太困了于是没做...第二天看题蘑菇题居多就只切了简单的两个... A:直接输出... int main() { //FIN; //FOUT; int x,y; cin>>x>> ...
- 上传excel数据到数据库中
上传excel表格数据到数据库 导入固定路径下的excel数据到数据库 <form id="disposeFlightDataForm" action="../up ...
- log4j.properties配置与加载应用
log4j.properties总结: 一.介绍 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务 器 ...
- 51NOD——T 1079 中国剩余定理
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难 ...