F - Courses (学生选课(匈牙利算法模板))
- 题目大意:一共有N个学生跟P门课程,一个学生可以任意选一门或多门课,问是否达成:
1.每个学生选的都是不同的课(即不能有两个学生选同一门课)
2.每门课都有一个代表(即P门课都被成功选过)
输入为:
P N(课程数跟学生数)
接着有P行,格式为Count studenti studenti+1 ……studentcount
(Count表示对课程1感兴趣的学生数,接着有Count个学生)
如第一行3 1 2 3表示学生1跟学生2跟学生3对课程1感兴趣
输出为:
若能满足上面两个要求这输出”YES”,否则为”NO”
. 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 <stdio.h>
- #include <algorithm>
- #include <iostream>
- #include <string.h>
- using namespace std;
- #define INF 0x3f3f3f3f
- #define N 310
- int dis[310],vis[310],dp[310][310];
- int n,m,t;
- int find(int x)
- {
- for(int i=1;i<=n;i++)
- {
- if(!vis[i]&&dp[x][i])
- {
- vis[i]=1;
- if(dis[i]==0||find(dis[i]))
- {
- dis[i]=x;
- return 1;
- }
- }
- }
- return 0;
- }
- int main()
- {
- cin>>t;
- while(t--)
- {
- int v,x;
- cin>>m>>n;
- int ans=0;
- memset(dp,0,sizeof(dp));
- memset(dis,0,sizeof(dis));
- for(int i=1;i<=m;i++)
- {
- cin>>v;
- while(v--)
- {
- cin>>x;
- dp[i][x]=1;
- }
- }
- for(int i=1;i<=m;i++)
- {
- memset(vis,0,sizeof(vis));
- if(find(i))
- ans++;
- }
- if(ans==m) printf("YES\n");
- else printf("NO\n");
- }
- }
F - Courses (学生选课(匈牙利算法模板))的更多相关文章
- poj 1274 The Perfect Stall【匈牙利算法模板题】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20874 Accepted: 942 ...
- 匈牙利算法模板 hdu 1150 Machine Schedule(二分匹配)
二分图:https://blog.csdn.net/c20180630/article/details/70175814 https://blog.csdn.net/flynn_curry/artic ...
- hdu 2063 过山车 (最大匹配 匈牙利算法模板)
匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最 ...
- 匈牙利 算法&模板
匈牙利 算法 一. 算法简介 匈牙利算法是由匈牙利数学家Edmonds于1965年提出.该算法的核心就是寻找增广路径,它是一种用增广路径求二分图最大匹配的算法. 二分图的定义: 设G=(V,E)是一个 ...
- HDU 1045 - Fire Net - [DFS][二分图最大匹配][匈牙利算法模板][最大流求二分图最大匹配]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1045 Time Limit: 2000/1000 MS (Java/Others) Mem ...
- HDU 2444 - The Accomodation of Students - [二分图判断][匈牙利算法模板]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=2444 Time Limit: 5000/1000 MS (Java/Others) Mem ...
- POJ:3041-Asteroids(匈牙利算法模板)
传送门:http://poj.org/problem?id=3041 Asteroids Time Limit: 1000MS Memory Limit: 65536K Description Bes ...
- POJ 1325 && 1274:Machine Schedule 匈牙利算法模板题
Machine Schedule Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 12976 Accepted: 5529 ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
随机推荐
- ElasticSearch- 单节点 unassigned_shards 故障排查
故障现象 在部署ELK的单机环境,当连接Kibana时候提示下面错误,即使重启整个服务也是提示Kibana server is not ready. {"message":&quo ...
- 利用GPU实现大规模动画角色的渲染(转)
原文: https://www.cnblogs.com/murongxiaopifu/p/7250772.html 利用GPU实现大规模动画角色的渲染 0x00 前言 我想很多开发游戏的小伙伴都希望自 ...
- 【MyBatis】MyBatis 延迟加载策略
MyBatis 延迟加载策略 文章源码 什么是延迟加载 延迟加载,就是在需要用到数据时才进行加载,不需要用到数据时就不加载数据,也被成为懒加载. 好处:先从单表查询,需要时再从关联表去关联查询,大大提 ...
- mmall商城用户模块开发总结
1.需要实现的功能介绍 注册 登录 用户名校验 忘记密码 提交问题答案 重置密码 获取用户信息 更新用户信息 退出登录 目标: 避免横向越权,纵向越权的安全漏洞 MD5明文加密级增加的salt值 Gu ...
- Linux find 命令的初步实现(C++)
Implement a myfind command following the find command in UNIX operating system. The myfind command s ...
- Burp suite的系列介绍 (1)
前言 为了进行Web安全方面的学习,Burp suite是必备的工具之一,我们将会从多个模块进行逐步的学习. Burp suite的应用场景 1.HTTP服务端接口测试. 2.HTTP客户端和HTTP ...
- 【Oracle】表空间配额问题
由于需求,需要新建用户,但是新建的用户,会有相关的配额跟着,莫名其妙的问题让人很头疼 下面介绍下如何修改成不限制配额 select * from user_ts_quotas ; alter user ...
- ECC 6 debuging中create points
2013-12-07 今天无意中,发现,在ECC6中debug的时候,创建动态断点,对于command中的delete from语句居然无效,唉 虽然设置了DELETE 和DELETE FROM两个动 ...
- 解决maven中某些依赖无法下载,手动安装Maven依赖
<!--先下载jar包,然后在仓库中手动安装,下面是遇到的两个例子--> <!--第一个--> mvn install:install-file -Dfile=D:\kaptc ...
- 如何在C#中使用MSMQ
MSMQ (Microsoft消息队列)是Windows中默认可用的消息队列.作为跨计算机系统发送和接收消息的可靠方法,MSMQ提供了一个可伸缩.线程安全.简单和使用方便的队列,同时为你提供了在Win ...