题目链接: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. janos.io

    http://janos.io/ https://developer.mozilla.org/en-US/Firefox_OS/Developing_Firefox_OS/Porting

  2. js中Object.defineProperties 定义一个在原对象可读可写的方法

    function A(){ this.name = 'hellow word'; } Object.defineProperties( A.prototype,{ doSomething2 : { v ...

  3. Spring_Learn

    IOC  控制反转,或者依赖注入  控制权的转移,应用程序本身不负责依赖对象的创建和维护.而是由外部容器负责创建和维护. DI(依赖注入)是其实现的一种方式 创建对象并且组装对象之间的关系. 1Spr ...

  4. Oracle 练习

    --简单的select语句select deptno,dname,loc from DEPT where deptno='40';--描述表结构 部门表desc dept;--雇员表desc emp; ...

  5. 51Nod 飞行员配对(二分图最大匹配)(匈牙利算法模板题)

    第二次世界大战时期,英国皇家空军从沦陷国征募了大量外籍飞行员.由皇家空军派出的每一架飞机都需要配备在航行技能和语言上能互相配合的2名飞行员,其中1名是英国飞行员,另1名是外籍飞行员.在众多的飞行员中, ...

  6. pycharm不显示工具栏,自动导入模块,格式化代码快捷键

    我们需修改View里面的Toolbar,在前面打上沟,然后就可以显示了 自动导入模块设置:import numpy as np 我们需用鼠标选中numpy,然后在键盘上同时按住Alt+Enter键,通 ...

  7. CODEVS——T 3013 单词背诵

    http://codevs.cn/problem/3013/  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond 题解  查看运行结果     题目描述 De ...

  8. android notify

    notify http://examples.javacodegeeks.com/android/core/ui/notifications/android-notifications-example ...

  9. XML Pull

    java [android]xml  new parse tool XML parsing with XML Pull import org.xmlpull.v1.XmlPullParser;

  10. POJ 1738 An old Stone Game(石子合并 经典)

    An old Stone Game Time Limit: 5000MS   Memory Limit: 30000K Total Submissions: 3672   Accepted: 1035 ...