博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Courses(最大匹配)
阅读量:6508 次
发布时间:2019-06-24

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

Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)

Total Submission(s): 5214    Accepted Submission(s): 2502

Problem 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:
 

 

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
题解:选课,每门课程至少有一个学生;
代码:
1 #include
2 #include
3 #include
4 #include
5 #include
6 #include
7 #define mem(x,y) memset(x,y,sizeof(x)) 8 using namespace std; 9 const int INF=0x3f3f3f3f;10 const int MAXN=350;11 vector
vec[MAXN];12 int usd[MAXN],vis[MAXN];13 bool dfs(int x){14 for(int i=0;i

 

转载地址:http://rjwfo.baihongyu.com/

你可能感兴趣的文章
win7 下硬盘安装Redhat7
查看>>
Configuring Zookeeper Cluster
查看>>
js图表控件:highcharts的应用
查看>>
Redis 分布式锁的正确实现方式
查看>>
mysqldump 备份命令使用中的一些经验总结
查看>>
Linux下MySql安装配置方法总结
查看>>
本IT博客用于域名投资、互联网、资源下载等相关干货收藏和学习
查看>>
ArrayList底层实现
查看>>
QNAP TS-219P NAS容量扩充
查看>>
DTOC( ) 函数
查看>>
初始化inittab文件丢失及修复
查看>>
emma杂记
查看>>
我的友情链接
查看>>
centos7 firewalld防火墙
查看>>
shell中检查某个命令是否存在
查看>>
【转载】Java程序设计入门 (二)
查看>>
第六天 if if…else 三木运算符
查看>>
新建文章 1
查看>>
which、whereis、location和fand的区别
查看>>
IP地址和子网划分学习笔记之《子网掩码详解》
查看>>