hdu 1083 Courses (最大匹配)
Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 10769 Accepted Submission(s): 5077
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:
Count1 Student1 1 Student1 2 ... Student1 Count1
Count2 Student2 1 Student2 2 ... Student2 Count2
......
CountP StudentP 1 StudentP 2 ... StudentP CountP
2
3 3
3 1 2 3
2 1 2
1 1
3 3
2 1 3
2 1 3
1 1
YES
NO
C/C++:
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <string>
#include <cstdio>
#include <cstring>
#include <climits>
#include <iostream>
#include <algorithm>
#define INF 0xffffff
using namespace std;
const int my_max = ; int P, N, my_line[my_max][my_max], my_book[my_max], my_right[my_max], b, n, my_ans; bool my_dfs(int x)
{
for (int i = ; i <= N; ++ i)
{
if (!my_book[i] && my_line[x][i])
{
my_book[i] = ;
if (!my_right[i] || my_dfs(my_right[i]))
{
my_right[i] = x;
return true;
}
}
}
return false;
} int main()
{
int t;
scanf("%d", &t);
while (t --)
{
my_ans = ;
memset(my_line, , sizeof(my_line));
memset(my_right, , sizeof(my_right)); scanf("%d%d", &P, &N);
for (int i = ; i <= P; ++ i)
{
scanf("%d", &n);
while (n --)
{
scanf("%d", &b);
my_line[i][b] = ;
}
} for (int i = ; i <= P; ++ i)
{
memset(my_book, , sizeof(my_book));
if (my_dfs(i)) my_ans ++;
} if (my_ans == P)
printf("YES\n");
else
printf("NO\n");
}
return ;
}
hdu 1083 Courses (最大匹配)的更多相关文章
- HDU 1083 Courses 【二分图完备匹配】
传送门:http://acm.hdu.edu.cn/showproblem.php?pid=1083 Courses Time Limit: 20000/10000 MS (Java/Others) ...
- hdu 1083 Courses(二分图最大匹配)
题意: P门课,N个学生. (1<=P<=100 1<=N<=300) 每门课有若干个学生可以成为这门课的代表(即候选人). 又规定每个学生最多只能成为一门课的代 ...
- HDU 1083 Courses(最大匹配模版题)
题目大意: 一共有N个学生跟P门课程,一个学生可以任意选一 门或多门课,问是否达成: 1.每个学生选的都是不同的课(即不能有两个学生选同一门课) 2.每门课都有一个代表(即P门课都被成功选过 ...
- HDU 1083 - Courses - [匈牙利算法模板题]
题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=1083 Time Limit: 20000/10000 MS (Java/Others) M ...
- HDU - 1083 Courses /POJ - 1469
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...
- hdu - 1083 - Courses
题意:有P门课程,N个学生,每门课程有一些学生选读,每个学生选读一些课程,问能否选出P个学生组成一个委员会,使得每个学生代言一门课程(他必需选读其代言的课程),每门课程都被一个学生代言(1 <= ...
- HDU 1083 Courses(二分图匹配模板)
http://acm.hdu.edu.cn/showproblem.php?pid=1083 题意:有p门课和n个学生,每个学生都选了若干门课,每门课都要找一个同学来表演,且一个同学只能表演一门课,判 ...
- HUD——1083 Courses
HUD——1083 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Ot ...
- (匹配)Courses -- hdu --1083
链接: http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://acm.hust.edu.cn/vjudge/contest/view.action ...
随机推荐
- 算法<初级> - 第一章 排序相关问题
算法 - 第一章 时间复杂度: Big O 时间/空间复杂度计算一样,都是跟输入数据源的大小有关 n->∞ O(logn) 每次只使用数据源的一半,logn同理 最优解 先满足时间复杂度的情况最 ...
- Linux常用命令-不定时记录
文件移动命令 命令格式:mv [-fiv] source destination 参数说明:-f:force,强制直接移动而不询问-i:若目标文件(destination)已经存在,就会询问是否覆盖- ...
- LogViewer解君之忧
LogViewer是一款查看和搜索大型文本文件的工具,能够很快速的查看记事本无法打开的大容量文件,比如大数据的日志文件或数据库文件等,可支持最大4GB的大容量. 一.下载地址链接(中文破解版): ht ...
- (乱入)FingerGesture
偶然的机会遇到FingerGesture插件,此插件也有很多方便的功能,比如控制主相机查看模型以及缩放等功能,如Component-FingerGestures-Toolbox-Camera-Orbi ...
- SpringBoot系列之@Value和@ConfigurationProperties
继上一篇博客SpringBoot系列之YAML配置用法之后,再写一篇@Value.@ConfigurationProperties的对比博客 这两个主键都是可以获取配置文件属性的,不过是有比较大的区别 ...
- redis is configured to save RDB snapshots
Redis被配置为保存数据库快照,但它目前不能持久化到硬盘.用来修改集合数据的命令不能用 原因: 强制关闭Redis 快照导致不能持久化. 解决方法: 运行 config set stop-write ...
- 激活Sublime Text 3,亲测有效!
一.修改sunlime_text.exe 打开Sublime Text的安装目录,在修改之前要先备份一下sunlime_text.exe. 欢迎关注微信公众号:万猫学社,每周一分享Java技术干货. ...
- Angular工作笔记(2018/8/8)
需求1:input标签只允许输入数字且不会出现上下选择按钮 开始设置 type="number" 客户不想要出现上下选择按钮 解决方法: 但是这种写法会有一个限制,只能输入整数,无 ...
- 【长期维护】C++休闲(修仙)躲方块小游戏
左右键控制小球左右移动,上键加速,Esc退出. 一个‘@’20分 #include <windows.h> #include <bits/stdc++.h> #include ...
- [考试反思]1023csp-s模拟测试83:等候
分数倒是依旧那么烂,但是这个时间比较诡异. 6分49秒弄出T1,15分钟送上T2的50分暴力,不到一小时半的时候T3的30分暴力也完成了... 在85分钟之后一次提交也没有 前15分钟平均每分钟得10 ...