hdu1083
#include"stdio.h"
#include"string.h"
#define N 305
int mark[N],link[N],map[N][N],p;
int find(int a) //匈牙利算法,二分匹配
{
int i;
for(i=1;i<=p;i++)
{
if(!mark[i]&&map[a][i])
{
mark[i]=1;
if(!link[i]||find(link[i]))//若i已经配对,则查找和i配对的
{ //那个元素是否还能和其他元素配对
link[i]=a;
return 1;
}
}
}
return 0;
}
int main()
{
int t,n,i,a,m,ans;
scanf("%d",&t);
while(t--)
{
memset(link,0,sizeof(link));
memset(map,0,sizeof(map));
scanf("%d%d",&p,&n);
for(i=1;i<=p;i++)
{
scanf("%d",&m);
while(m--)
{
scanf("%d",&a);
map[a][i]=1;
}
}
ans=0;
for(i=1;i<=n;i++)
{
memset(mark,0,sizeof(mark));
ans+=find(i);
}
if(ans==p) //最大匹配数等于课程数
printf("YES\n");
else
printf("NO\n");
}
return 0;
}
hdu1083的更多相关文章
- hdu2063+hdu1083(最大匹配数)
传送门:hdu2063过山车 #include <cstdio> #include <cstring> #include <string> #include < ...
- HDU1083 Courses —— 二分图最大匹配
题目链接:https://vjudge.net/problem/HDU-1083 Courses Time Limit: 20000/10000 MS (Java/Others) Memory ...
- HDU-1083 Courses 二分图 最大匹配
题目链接:https://cn.vjudge.net/problem/HDU-1083 题意 有一些学生,有一些课程 给出哪些学生可以学哪些课程,每个学生可以选多课,但只能做一个课程的代表 问所有课能 ...
- hdu1083二分图匹配模板题
onsider a group of N students and P courses. Each student visits zero, one or more than one courses. ...
- Hdu1083 Courses
Courses Problem Description Consider a group of N students and P courses. Each student visits zero, ...
- HDU1083(KB10-C 二分图最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- COURSES---poj1469 hdu1083(最大匹配)
题目链接:http://poj.org/problem?id=1469 http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有n个学生p门课, 每门 ...
- HDU1083 :Courses(二分图匹配)
Cources Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU-1083
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU1083(二分图最大匹配vector实现)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
随机推荐
- In a Web Application and Mobile (hybrid), how to know which this platform running?
needed depending on the platform to change the CSS to suit the size of the font. for example the DbG ...
- LINQ 学习路程 -- 查询操作 OrderBy & OrderByDescending
Sorting Operator Description OrderBy 通过给定的字段进行升序 降序 排序 OrderByDescending 通过给定字段进行降序排序,仅在方法查询中使用 Then ...
- QT 按键处理 快捷键处理 shift + ctrl
原味地址:http://www.cnblogs.com/codingmylife/archive/2010/08/30/1812739.html CTRL+Enter发送信息的实现 在现在的即时聊天程 ...
- D. String Game 二分加字符串匹配
题目链接 题目大意:给出字符串str1,再第二行给出字符串str2,第三行给出删除str1中的字符的顺序,用数组a[]存,问最多按第三行的顺序删除str1中的字符剩下的字符串中str2 我们定义l为a ...
- 关于MFC中重载函数是否调用基类相对应函数的问题
在重载CDialog的OnInitDialog()函数的时候,在首行会添加一句:CDialongEx::OnInitDialog();语句,这是为什么呢?什么时候添加,什么时候不添加? 实际上,我们在 ...
- VScode 为 *.cu文件 添加高亮及c++ intelligence相关操作的方法
问题:*.cu在VScode不能像*.cc或*.cpp一样在c++及c++ intelligence插件有关键字的高亮以及go to definition等的操作 解决方案:添加*.cu与*.cpp文 ...
- 【二叉树的递归】03判断二叉树中有没有和为给定值的路径【Path Sum】
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 给定一个二叉树和一个和,判断这个树 ...
- FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题--转
FEC(Forward Error Correction)前向纠错 UDP\RTP 中使用用于改善无线等网络丢包等问题 算法暂不介绍. 思路:FEC ENCODE 增加冗余包,当无线等网络丢包之后,接 ...
- openfire存储中文字符乱码解决办法
转载于: Xmpp问题总结:处理Openfire 中文乱码问题(2) openfire是一个非常不错的IM服务器,而且是纯Java实现,具有多个平台的版本,他的数据存储可以采用多种数据库,如MySQL ...
- 【转】Pro Android学习笔记(十二):了解Intent(下)
解析Intent,寻找匹配Activity 如果给出component名字(包名.类名)是explicit intent,否则是implicit intent.对于explicit intent,关键 ...