题目链接: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. ElasticSearch vs 关系型数据库

    它们之间的关系,如下图所示.

  2. Kinect 开发 —— 硬件设备解剖

    Kinect for Xbox: 360 不支持“近景模式” 三只眼睛 —— 红外投影机,RGB摄像头,红外深度投影头  —— 色彩影像中的每个像素分别与深度影像中的一个像素对应 四只耳朵 —— L形 ...

  3. 【例题 8-13 UVA - 11093】Just Finish it up

    [链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 尺取法. 假设现在取[l..r]这一段. 然后发现累加的和小于0了. 那么方法只能是不走l..l+1这一段了 即delta递减(p[ ...

  4. Linux 获取上个月的第一秒和上个月的最后一秒

    因为写脚本需求须要获得上个月的第一秒和上个月的最后一秒,查阅了相关资料,并通过自己实践.找到了以下这样的方法能满足要求.在此备注,若有其它好的方法.请留言.本人将不胜感激. 获取上个月的第一秒: da ...

  5. Oracle APEX 4.2公布RESTful Webservice

    Purpose This tutorial covers creating a RESTful Web Service and accessing the Web Service through an ...

  6. JS 图片大小自动调整 (img)

    <script> function dlutChangeImg(){ var maxwidth = 598; var obj = document.getElementById('bbs_ ...

  7. php课程 13-43 mysql的数据结构是什么

    php课程 13-43 mysql的数据结构是什么 一.总结 一句话总结:cs结构,客户端,服务器 1.常用的比较出名的数据库有哪些? SQL数据库(关系型):1.收费:DB2SqlserverOra ...

  8. 妙味css3课程---1-2、css3中新增的伪类和伪元素有哪些

    妙味css3课程---1-2.css3中新增的伪类和伪元素有哪些 一.总结 一句话总结: 1.div:target{}是什么意思? 比如a标签的锚点链接到div,div:target{}就可以找到这个 ...

  9. javafx spring

    javafx spring http://files.cnblogs.com/files/rojas/airhacks_control.zip

  10. CISP/CISA 每日一题 17

     CISSP 每日一题(答) What are often added to passwords to maketheir resultant hash secure and resistant to ...