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

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个人,输出是否所有人都可以选择自己的星球。
 
此题数据绝对很水,我不小心把写成match[][15]这都能过,哈哈哈。
多重匹配转换为最大匹配,把n个容量拆成n个点。
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. int n,m;
  5. int maps[][];
  6. int match[][];
  7. int cnt[];
  8. bool use[];
  9. int cap[];
  10.  
  11. bool DFS(int u)
  12. {
  13. for(int i=; i<m; i++)
  14. {
  15. if(!use[i]&&maps[u][i])
  16. {
  17. use[i] = true;
  18. if(cnt[i]<cap[i])
  19. {
  20. match[i][cnt[i]++] = u;
  21. return true;
  22. }
  23. else
  24. {
  25. for(int j=; j<cap[i]; j++)
  26. {
  27. if(DFS(match[i][j])==true)
  28. {
  29. match[i][j] = u;
  30. return true;
  31. }
  32. }
  33. }
  34. }
  35. }
  36. return false;
  37. }
  38.  
  39. int main()
  40. {
  41. while(~scanf("%d%d",&n,&m))
  42. {
  43. memset(match,-,sizeof(match));
  44. memset(maps,,sizeof(maps));
  45. memset(cap,,sizeof(cap));
  46. memset(cnt,,sizeof(cnt));
  47. for(int i=; i<n; i++)
  48. for(int j=; j<m; j++)
  49. scanf("%d",&maps[i][j]);
  50. for(int i=; i<m; i++)
  51. scanf("%d",&cap[i]);
  52.  
  53. bool flag = true;
  54. for(int i=; i<n; i++)
  55. {
  56. memset(use,false,sizeof(use));
  57. if(DFS(i)==false)
  58. {
  59. flag = false;
  60. break;
  61. }
  62. }
  63. if(flag) puts("YES");
  64. else puts("NO");
  65. }
  66. return ;
  67. }
 
 

HDU(3605),二分图多重匹配的更多相关文章

  1. hdu 3605(二分图多重匹配)

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

  2. HDU 1669 二分图多重匹配+二分

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  3. hdu 1669(二分图多重匹配)

    Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/ ...

  4. HDU 3609 二分图多重匹配

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

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

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

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

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

  7. HDU3605 Escape —— 二分图多重匹配

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

  8. kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树

    二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...

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

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

  10. 【POJ 1698】Alice's Chance(二分图多重匹配)

    http://poj.org/problem?id=1698 电影和日子匹配,电影可以匹配多个日子. 最多有maxw*7个日子. 二分图多重匹配完,检查一下是否每个电影都匹配了要求的日子那么多. #i ...

随机推荐

  1. 如何准确进行T+0操作

    如何准确进行T+0操作 http://tangulunjin.com.cn/t0.html 常用的几种T+0模式 1.受外盘或者个股利好高开,高开一般在10点之前会有个回抽昨日收盘价的下跌波.特别是弱 ...

  2. struts2 标签字体大小

    <style type="text/css"> label{ font-size: 20px; } </style> <s:textfield nam ...

  3. Java基础(8):方法重载的4个依据与例子

    判断方法重载的依据: 1. 必须是在同一个类中 2. 方法名相同 3. 方法参数的个数.顺序或类型不同 4. 与方法的修饰符或返回值没有关系 运行结果:

  4. java中Date的getTime() 方法奇葩问题

    今天遇到了一个奇葩问题: 从数据库中读取了3个Date类型的数据: DATE1:2015-03-12 12:10:42 DATE2:2015-03-12 12:04:40 DATE3:2015-03- ...

  5. MVC4下拉少数名族

    List<SelectListItem> nationlist = new List<SelectListItem>() { new SelectListItem(){Valu ...

  6. mysql设置时区方法

    set global time_zone = '+2:00'; ##修改mysql全局时区 set time_zone = '+2:00'; ##修改当前会话时区 flush privileges; ...

  7. 仅支持webkit浏览器的多行内容超出显示省略号

    .box { display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; ...

  8. android 项目学习随笔一(闪屏 )

    1.取标题栏且全屏 <activity android:name="com.ecollab.zhsh66.SplashActivity" android:label=&quo ...

  9. source insight资源

    http://www.cnblogs.com/Red_angelX/p/3713935.html https://github.com/redxu/sihook

  10. linux设备驱动归纳总结(八):1.总线、设备和驱动【转】

    本文转载自:http://blog.chinaunix.net/uid-25014876-id-109733.html linux设备驱动归纳总结(八):1.总线.设备和驱动 xxxxxxxxxxxx ...