hdu 1669(二分图多重匹配)
Jamie's Contact Groups
Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)
Total Submission(s): 552 Accepted Submission(s): 190
is a very popular girl and has quite a lot of friends, so she always
keeps a very long contact list in her cell phone. The contact list has
become so long that it often takes a long time for her to browse through
the whole list to find a friend's number. As Jamie's best friend and a
programming genius, you suggest that she group the contact list and
minimize the size of the largest group, so that it will be easier for
her to search for a friend's number among the groups. Jamie takes your
advice and gives you her entire contact list containing her friends'
names, the number of groups she wishes to have and what groups every
friend could belong to. Your task is to write a program that takes the
list and organizes it into groups such that each friend appears in only
one of those groups and the size of the largest group is minimized.
will be at most 20 test cases. Ease case starts with a line containing
two integers N and M. where N is the length of the contact list and M is
the number of groups. N lines then follow. Each line contains a
friend's name and the groups the friend could belong to. You can assume N
is no more than 1000 and M is no more than 500. The names will contain
alphabet letters only and will be no longer than 15 characters. No two
friends have the same name. The group label is an integer between 0 and M
- 1. After the last test case, there is a single line `0 0' that
terminates the input.
John 0 1
Rose 1
Mary 1
5 4
ACM 1 2 3
ICPC 0 1
Asian 0 2 3
Regional 1 2
ShangHai 0 2
0 0
2
#include<iostream>
#include<cstdio>
#include<cstring>
#include <algorithm>
#include <math.h>
using namespace std;
const int N = ;
int n,m,cap;
char str[];
int graph[N][N];
int linker[N][N],link[N];
bool vis[N];
bool dfs(int u){ ///多重匹配,从一端到多端进行匹配
for(int v=;v<m;v++){
if(graph[u][v]&&!vis[v]){
vis[v] = true;
if(link[v]<cap){
linker[v][link[v]++] = u;
return ;
}
for(int i=;i<link[v];i++){
if(dfs(linker[v][i])){
linker[v][i] = u;
return true;
}
}
}
}
return false;
}
bool match(int mid){
cap = mid;
memset(link,,sizeof(link));
for(int i=;i<n;i++){
memset(vis,false,sizeof(vis));
if(!dfs(i)) return false; ///找不到匹配点
}
return true;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF,n+m){
char c;
int v;
memset(graph,,sizeof(graph));
getchar();
for(int i=;i<n;i++){
scanf("%s",str);
while(scanf("%c",&c)&&c!='\n'){
scanf("%d",&v);
graph[i][v] = ;
}
}
int l = ,r = n,ans=n;
while(l<=r){
int mid = (l+r)>>;
if(match(mid)){
ans = mid;
r = mid-;
}else l = mid+;
}
printf("%d\n",ans);
}
return ;
}
hdu 1669(二分图多重匹配)的更多相关文章
- HDU 1669 二分图多重匹配+二分
Jamie's Contact Groups Time Limit: 15000/7000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/ ...
- hdu 3605(二分图多重匹配)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- hdu 1669(二分+多重匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1669 思路:由于要求minimize the size of the largest group,由此 ...
- HDU 3609 二分图多重匹配
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- HDU - 3605 Escape (缩点+最大流/二分图多重匹配)
题意:有N(1<=N<=1e5)个人要移民到M(1<=M<=10)个星球上,每个人有自己想去的星球,每个星球有最大承载人数.问这N个人能否移民成功. 分析:可以用最大流的思路求 ...
- HDU 3605 Escape(二分图多重匹配问题)
Escape Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)Total Subm ...
- kuangbin带你飞 匹配问题 二分匹配 + 二分图多重匹配 + 二分图最大权匹配 + 一般图匹配带花树
二分匹配:二分图的一些性质 二分图又称作二部图,是图论中的一种特殊模型. 设G=(V,E)是一个无向图,如果顶点V可分割为两个互不相交的子集(A,B),并且图中的每条边(i,j)所关联的两个顶点i和j ...
- HDU3605 Escape —— 二分图多重匹配
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=3605 Escape Time Limit: 4000/2000 MS (Java/Others) ...
- hihoCoder 1393 网络流三·二分图多重匹配(Dinic求二分图最大多重匹配)
#1393 : 网络流三·二分图多重匹配 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 学校的秋季运动会即将开始,为了决定参赛人员,各个班又开始忙碌起来. 小Hi和小H ...
随机推荐
- oop &&GP 模板 ---> 特化和偏特化
OOP面向对象编程 GP泛型编程(generic programming) 两者的主要区别就是OOP将数据和对数据的操作放在一起, GP就是将数据和操作独立开来 GP: 数据就是container ...
- LTE:上行调度请求(Scheduling Request,SR) LTE:下行资源分配类型
http://blog.sina.com.cn/s/blog_927cff010101a7yh.html 上行调度请求(Scheduling Request,SR) 如果UE没有上行数据要传输,eNo ...
- 【python】实现一个python编程的小时钟!
[本实验内容] 1.GUI.PyQT5介绍2.实现此次实验效果 [一 GUI.PyQt5介绍] 1.Python简介 2.GUI介绍 几个常用的Python GUI库: (1)wxPython (2) ...
- Java的同步容器和并发容器
前言: 之前在介绍Java集合的时候说到,java提供的实现类很少是线程安全的.只有几个比较古老的类,比如Vector.Hashtable等是线程安全的,尤其是Hashtable,古老到连命名规范都没 ...
- 【历史】- Unix时代的开创者Ken Thompson
自图灵奖诞生以来,其获得者一直都是计算机领域的科学家与学者,而在所有这些界的图灵奖中只有唯一的一届有个例外,那就是Ken Thompson与Dennis M. Ritchie,他们都是计算机软件工程师 ...
- 算法(9)Find the Duplicate Number
一个数组中的长度是n+1,里面存放的数字大小的范围是[1,n],根据鸽巢原理,所以里面肯定有重复的数字,现在预定重复的数字就1个,让你找到这个数字! http://bookshadow.com/web ...
- hihocoder 1320 压缩字符串(字符串+dp)
题解: 其实就是对应三种dp的转移方式 1.拼接类型 dp[i][j] = dp[i][c] + dp[c][j] 2.不变类型 dp[i][j] = j-i+1 3.重复类型(必须满足有k个循环节) ...
- luogu P2764 最小路径覆盖问题
题目描述 给定有向图G=(V,E).设P 是G 的一个简单路(顶点不相交)的集合.如果V 中每个顶点恰好在P 的一条路上,则称P是G 的一个路径覆盖.P 中路径可以从V 的任何一个顶点开始,长度也是任 ...
- 安徽师大附中%你赛day7 T2 乘积 解题报告
乘积 题目背景 \(\mathrm{Smart}\) 最近在潜心研究数学, 他发现了一类很有趣的数字, 叫做无平方因子数. 也就是这一类数字不能够被任意一个质数的平方整除, 比如\(6\).\(7\) ...
- 【BZOJ 1592】[Usaco2008 Feb]Making the Grade 路面修整 dp优化之转移变状态
我们感性可证离散(不离散没法做),于是我们就有了状态转移的思路(我们只考虑单不减另一个同理),f[i][j]到了第i块高度为j的最小话费,于是我们就可以发现f[i][j]=Min(f[i-1][k]) ...