博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
C - Courses
阅读量:5077 次
发布时间:2019-06-12

本文共 2934 字,大约阅读时间需要 9 分钟。

Description

Consider a group of N students and P courses. Each student visits zero, one or more than one courses. Your task is to determine whether it is possible to form a committee of exactly P students that satisfies simultaneously the conditions: 
. 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

23 33 1 2 32 1 21 13 32 1 32 1 31 1

Output

YESNO

Sample Input

23 33 1 2 32 1 21 13 32 1 32 1 31 1

Sample Output

YESNO
#include 
#include
#include
#include
#include
#include
#include
#include
#include
#include
using namespace std;#define met(a, b) memset(a, b, sizeof(a))#define N 303#define INF 0x3f3f3f3fconst int MOD = 1e9+7;typedef long long LL;int vis[N], used[N];///used[i]表示y集合中的点是否匹配;int G[N][N], p, n;bool Hungary(int u){ for(int i=1; i<=p; i++) { if(!vis[i] && G[u][i]) { vis[i] = 1; if(!used[i] || Hungary(used[i])) { used[i] = u; return true; } } } return false;}int main(){ int T; scanf("%d", &T); while(T--) { memset(G, 0, sizeof(G)); scanf("%d%d", &p, &n); for(int i=1; i<=p; i++) { int cnt, x; scanf("%d", &cnt); for(int j=1; j<=cnt; j++) { scanf("%d", &x); G[x][i] = 1; } } memset(used, 0, sizeof(used)); int ans = 0; for(int i=1;i<=n; i++) { memset(vis, 0, sizeof(vis)); if(Hungary(i)) ans++; } if(ans == p) puts("YES"); else puts("NO"); } return 0;}

 

转载于:https://www.cnblogs.com/biu-biu-biu-/p/5741673.html

你可能感兴趣的文章
Window 的引导过程
查看>>
App右上角数字
查看>>
从.NET中委托写法的演变谈开去(上):委托与匿名方法
查看>>
小算法
查看>>
201521123024 《java程序设计》 第12周学习总结
查看>>
新作《ASP.NET MVC 5框架揭秘》正式出版
查看>>
IdentityServer4-用EF配置Client(一)
查看>>
WPF中实现多选ComboBox控件
查看>>
读构建之法第四章第十七章有感
查看>>
Windows Phone开发(4):框架和页 转:http://blog.csdn.net/tcjiaan/article/details/7263146
查看>>
Unity3D研究院之打开Activity与调用JAVA代码传递参数(十八)【转】
查看>>
python asyncio 异步实现mongodb数据转xls文件
查看>>
TestNG入门
查看>>
【ul开发攻略】HTML5/CSS3菜单代码 阴影+发光+圆角
查看>>
[ZJOI2007]棋盘制作 【最大同色矩形】
查看>>
IOS-图片操作集合
查看>>
模板统计LA 4670 Dominating Patterns
查看>>
团队项目开发客户端——登录子系统的设计
查看>>
IO—》Properties类&序列化流与反序列化流
查看>>
session如何保存在专门的StateServer服务器中
查看>>