Courses HDU - 1083 (二分匹配模板题)
. every student in the committee represents a different course (a student can represent a course if he/she visits that course)
. each course has a representative in the committee
Your program should read sets of data from a text file. The first line of the input file contains the number of the data sets. Each data set is presented in the following format:
P N
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
......
CountP StudentP 1 StudentP 2 ... StudentP CountP
The first line in each data set contains two positive integers separated by one blank: P (1 <= P <= 100) - the number of courses and N (1 <= N <= 300) - the number of students. The next P lines describe in sequence of the courses . from course 1 to course P, each line describing a course. The description of course i is a line that starts with an integer Count i (0 <= Count i <= N) representing the number of students visiting course i. Next, after a blank, you'll find the Count i students, visiting the course, each two consecutive separated by one blank. Students are numbered with the positive integers from 1 to N.
There are no blank lines between consecutive sets of data. Input data are correct.
The result of the program is on the standard output. For each input data set the program prints on a single line "YES" if it is possible to form a committee and "NO" otherwise. There should not be any leading blanks at the start of the line.
An example of program input and output:
Input
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
Output
YES
NO
Sample Input
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
Sample Output
YES
NO
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
using namespace std;
#define MAXN 317
int LN,RN;//L,R数目
int g[MAXN][MAXN], linker[MAXN];
bool used[MAXN];
int dfs(int L)//从左边开始找增广路径
{
int R;
for(R = ; R <= RN; R++)
{
if(g[L][R]!= && !used[R])
{
//找增广路,反向
used[R]=true;
if(linker[R] == - || dfs(linker[R]))
{
linker[R]=L;
return ;
}
}
}
return ;//这个不要忘了,经常忘记这句
}
int hungary()
{
int res = ;
int L;
memset(linker,-,sizeof(linker));
for( L = ; L <= LN; L++)
{
memset(used,,sizeof(used));
if(dfs(L) != )
res++;
}
return res;
}
int main()
{
int t;
int p, n;
int k, L, R;
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&n);
memset(g,,sizeof(g));
for(int i = ; i <= p; i++)
{
scanf("%d",&k);
for(int j = ; j <= k; j++)
{
scanf("%d",&R);
L = i;
g[L][R] = ;
}
}
LN = p;
RN = n;
int res = hungary();//最大匹配数
//printf("%d\n",res);
if(res == p)
{
printf("YES\n");
}
else
{
printf("NO\n");
}
}
return ;
}
Courses HDU - 1083 (二分匹配模板题)的更多相关文章
- (匹配)Courses -- hdu --1083
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://acm.hust.edu.cn/vjudge/contest/view.action ...
- C - Courses - hdu 1083(模板)
一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过) 输入为: P N( ...
- HDU - 1054 Strategic Game (二分图匹配模板题)
二分图匹配模板题 #include <bits/stdc++.h> #define FOPI freopen("in.txt", "r", stdi ...
- hdu 4024 二分
转自:http://www.cnblogs.com/kuangbin/archive/2012/08/23/2653003.html 一种是直接根据公式计算的,另外一种是二分算出来的.两种方法速度 ...
- codeforces 1165F1/F2 二分好题
Codeforces 1165F1/F2 二分好题 传送门:https://codeforces.com/contest/1165/problem/F2 题意: 有n种物品,你对于第i个物品,你需要买 ...
- HDU 1083 - Courses - [匈牙利算法模板题]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...
- HDU 1083 Courses(二分图匹配模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...
- HDU 1083 Courses(最大匹配模版题)
题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过 ...
- hdu - 1083 - Courses
题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...
随机推荐
- 【转】VISUAL STUDIO 2008代码指标为您节省资金
转自:https://www.geekzone.co.nz/vs2008/4773 Visual Studio 2008 Team Developer和Team Suite版本中提供的许多新功能之一是 ...
- abp 嵌入资源(视图、css、js)的访问
最近在做的基于abp作为框架的一个项目,将一些属于框架功能的页面写在了一个独立程序集中,然后在web项目中引用该程序集达到访问框架页面目的. 这样一来发布web之后,在发布目录中是看不到写在另一个程序 ...
- odoo之可选择多个内容显示问题
<field name="partner_id" widget="many2many_tags" options="{'no_create': ...
- odoo开发历史订单需求整体思路
第一步:找到客户对应页面,并找到他所下过的销售订单,用数据库语句查出所有数据,并去除重复数据,显示在前端, sql="select DISTINCT t2.product_id as pro ...
- [SDOI2011]工作安排 BZOJ2245
分析: 费用流裸题,按照题面要求建边就可以了,语文题,我读了10多分钟才知道这题干啥...特别是注意一个细节a[j+1]-a[j]... 附上代码: #include <cstdio> # ...
- 20155226《网络攻防》 Exp5 MSF基础应用
20155226<网络攻防> Exp5 MSF基础应用 基础问题回答 1.用自己的话解释什么是exploit,payload,encode? exploit : Exploit的英文意思就 ...
- 2017-2018-2 20155310『网络对抗技术』Exp5:MSF基础应用
2017-2018-2 20155310『网络对抗技术』Exp5:MSF基础应用 基础问题回答 用自己的话解释什么是exploit,payload,encode exploit:由攻击者或渗透测试者利 ...
- 洛咕 P3700 [CQOI2017]小Q的表格
洛咕 P3700 [CQOI2017]小Q的表格 神仙题orz 首先推一下给的两个式子中的第二个 \(b\cdot F(a,a+b)=(a+b)\cdot F(a,b)\) 先简单的想,\(F(a,a ...
- 使用 idea 的Bookmarks(书签)功能
https://blog.csdn.net/qq_36376059/article/details/80277767
- Flutter - ListView禁止用户上下滑动
ListView禁止用户上下滑动可以使用physics属性 physics: const NeverScrollableScrollPhysics()