hdu 3065 二分图多重匹配
来源:互联网 发布:什么是键值数据库 编辑:程序博客网 时间:2024/06/05 03:28
题目链接点击打开链接
Escape
Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 11261 Accepted Submission(s): 2709
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
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.
If you can output YES, otherwise output NO.
Sample Input
1 1112 21 01 01 1
Sample Output
YESNO
Source
2010 ACM-ICPC Multi-University Training Contest(17)——Host by ZSTU
Recommend
lcy | We have carefully selected several similar problems for you: 2883 2732 3338 2485 3607
题目大意:有n个人要移民到m个星球,其中每个星球可以有多个移民但是。
这是典型的多重匹配问题
我们依旧用匈牙利算法来解决,只不过匈牙利算法中是开了一个一维数组来保存与y对应的x,这里会有多个x与y对应,因此我们就需要开一个二维数组来保存,数组的第一个下标表示y的序号,第二个下标表示与y对应的是第几个x的序号。我们在给X配对时,如果所对应的Y没有达到限制,就直接让两者配对,否则我们就让与Y对应的其他几个X让位置,并且注意要记录与Y匹配的X的数量是几个。
AC代码:
#include<iostream>#include<string.h>#include<stdio.h>using namespace std;int n,m;int map[100010][11];int together[11][100010];bool check[11];bool flag;int a[11];int cnt[11];bool dfs(int x){ for(int j=1;j<=m;j++) { if(map[x][j]&&!check[j]) { check[j]=true; if(cnt[j]<a[j]) { together[j][++cnt[j]]=x; return true; } for(int k=1;k<=cnt[j];k++) { if(dfs(together[j][k])) { together[j][k]=x; return true; } } } } return false;}int main(){ while(~scanf("%d%d",&n,&m)) { flag=false; memset(cnt,0,sizeof(cnt)); for(int i=1;i<=n;i++) for(int j=1;j<=m;j++) scanf("%d",&map[i][j]); for(int i=1;i<=m;i++) scanf("%d",&a[i]); for(int i=1;i<=n;i++) { memset(check,false,sizeof(check)); if(!dfs(i)) { flag=true; break; } } if(flag) printf("NO\n"); else printf("YES\n"); } return 0;}
阅读全文
0 0
- hdu 3065 二分图多重匹配
- hdu 3605 二分图多重匹配
- hdu 3605 二分图多重匹配
- hdu 3605 Escape (二分图多重匹配)
- hdu 3605 Escape【二分图多重匹配】
- 二分图多重匹配(HDU 2255)
- HDU 3605 Escape【二分图多重匹配】
- hdu 3605 二分图多重匹配
- HDU 1669 二分+多重匹配
- hdu 1669(二分图多重匹配+二分枚举)
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- 二分图多重匹配
- hdu 3605 Escape(二分图多重匹配问题)
- 解决用PLSQL Developer连接VMWare中的Oracle 11g问题
- 解读 redux 的设计思路与用法
- 实验A—2 约瑟夫环问题
- 数据结构中常见的树(BST二叉搜索树、AVL平衡二叉树、RBT红黑树、B-树、B+树、B*树)
- C++中的enum(枚举)简介
- hdu 3065 二分图多重匹配
- this
- 进程管理工具 supervisord 即使supervisorctl 命令的使用
- 218
- mysql行转列sql
- Eclipse常见快捷键
- 西南交通大学第十三届ACM决赛 D.Music Problem 背包DP
- study-32:Shell(二)
- poi翻译-Busy Developers' Guide to HSSF and XSSF Features