题目链接: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): 8001    Accepted Submission(s): 1758

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
 
Source

题目大意: N(N<100,000)个人要去M(M<10)个星球。每一个人仅仅能够去一些星球。一个星球最多容纳Ki个人。输出是否全部人都能够选择自己的星球。

解题思路:放置了非常久的题目了,一直是TLE,今天翻出来改来改去还是TLE~~~~大过春节的,非要AC。
由于n非常大,m非常小。标记的数组不要太大,15就足够啦。解决多重匹配就是记录一下多重匹配的点(简称Y方点)已经匹配了Pi个点。

假设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 二分图的多重匹配(匈牙利算法)的更多相关文章

  1. HDU 5943 Kingdom of Obsession 【二分图匹配 匈牙利算法】 (2016年中国大学生程序设计竞赛(杭州))

    Kingdom of Obsession Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Oth ...

  2. hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)

    #1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...

  3. USACO 4.2 The Perfect Stall(二分图匹配匈牙利算法)

    The Perfect StallHal Burch Farmer John completed his new barn just last week, complete with all the ...

  4. HDU 3605 Escape (网络流,最大流,位运算压缩)

    HDU 3605 Escape (网络流,最大流,位运算压缩) Description 2012 If this is the end of the world how to do? I do not ...

  5. Hdu 3605 Escape (最大流 + 缩点)

    题目链接: Hdu 3605  Escape 题目描述: 有n个人要迁移到m个星球,每个星球有最大容量,每个人有喜欢的星球,问是否所有的人都能迁移成功? 解题思路: 正常情况下建图,不会爆内存,但是T ...

  6. HDU - 3605 Escape (缩点+最大流/二分图多重匹配)

    题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...

  7. HDU 3605 Escape(二分图多重匹配问题)

    Escape Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Subm ...

  8. HDU(3605),二分图多重匹配

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

  9. hdu 2063 给男女匹配 (匈牙利算法)

    来源:http://acm.hdu.edu.cn/showproblem.php?pid=2063 题意: 有k个组合a,b组合,代表a愿意与b坐过山车,共m个女生 n个男生,问有多少个满意的匹配 题 ...

随机推荐

  1. css3新特性选择器(补充)

    1.选择p标签中的第一个字符 p:first-letter{ color:red; font-size:25px; } 2.选择p标签中的第一行 p:first-line{ color:red; fo ...

  2. springboot扫描通用的依赖模块

    将实际使用类的启动类改为如下形式启动: public class OrderApplication { public static void main(String[] args) { Object[ ...

  3. 【DRF路由】

    在urls.py文件中按照如下步骤写,即可正确使用DRF的内置路由. from .views import BookModel # 1. 导入我们的视图 from rest_framework.rou ...

  4. Linux下关机命令的区别 (halt,poweroff,reboot,shutdown,init)

    1.shutdown shutdown命令安全地将系统关机.    而在系统关机前使用shutdown命令﹐系统管理员会通知所有登录的用户系统将要关闭.并且login指令会被冻结﹐即新的用户不能再登录 ...

  5. 【2017 Multi-University Training Contest - Team 3】RXD and math

    [Link]: [Description] [Solution] 发现1010mod(109+7)=999999937; 猜测答案是nk 写个快速幂; 注意对底数先取模; [NumberOf WA] ...

  6. 【剑指Offer面试题】九度OJ1384:二维数组中的查找

    下决心AC全部剑指offer面试题. 九度OJ面试题地址:http://ac.jobdu.com/hhtproblems.php 书籍:何海涛--<剑指Offer:名企面试官精讲典型编程题> ...

  7. Codeforces Round #195 (Div. 2) 少部分题解

    太困了于是没做...第二天看题蘑菇题居多就只切了简单的两个... A:直接输出... int main() { //FIN; //FOUT; int x,y; cin>>x>> ...

  8. 上传excel数据到数据库中

    上传excel表格数据到数据库 导入固定路径下的excel数据到数据库 <form id="disposeFlightDataForm" action="../up ...

  9. log4j.properties配置与加载应用

    log4j.properties总结:   一.介绍 Log4j是Apache的一个开放源代码项目,通过使用Log4j,我们可以控制日志信息输送的目的地是控制台.文件.GUI组件.甚至是套接口服务 器 ...

  10. 51NOD——T 1079 中国剩余定理

    http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1079 基准时间限制:1 秒 空间限制:131072 KB 分值: 0 难 ...