POJ1469_COURSES(二部图最大匹配)
解决报告
http://blog.csdn.net/juncoder/article/details/38136065
题意:
n个学生p门课程,每一个学生学习0或1以上的课程。
问:能否够组成委员会。满足
每一个学生代表一门不同的课程
一门课程在委员会中有一名代表
思路:
非常明显的二分图的完备匹配。
#include <map>
#include <queue>
#include <vector>
#include <cstdio>
#include <cstring>
#include <iostream>
#define N 330
#define P 110
using namespace std;
int mmap[N+P][N+P],n,p,pre[N+P],vis[N+P],m,k;
int dfs(int x)
{
for(int i=p+1;i<=p+n;i++)
{
if(!vis[i]&&mmap[x][i])
{
vis[i]=1;
if(pre[i]==-1||dfs(pre[i]))
{
pre[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,t;
while(~scanf("%d",&t))
{
while(t--)
{
memset(mmap,0,sizeof(mmap));
memset(pre,-1,sizeof(pre));
scanf("%d%d",&p,&n);
for(i=1;i<=p;i++)
{
scanf("%d",&m);
for(j=1;j<=m;j++)
{
scanf("%d",&k);
mmap[i][k+p]=1;
}
}
int ans=0;
for(i=1;i<=p;i++)
{
memset(vis,0,sizeof(vis));
ans+=dfs(i);
}
if(ans==p)
printf("YES\n");
else printf("NO\n");
}
}
return 0;
}
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 17166 | Accepted: 6748 |
Description
- 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
Input
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抣l 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.
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
Source
版权声明:本文博主原创文章,博客,未经同意不得转载。
POJ1469_COURSES(二部图最大匹配)的更多相关文章
- POJ1274 The Perfect Stall【二部图最大匹配】
主题链接: id=1274">http://poj.org/problem? id=1274 题目大意: 有N头奶牛(编号1~N)和M个牛棚(编号1~M). 每头牛仅仅可产一次奶.每一 ...
- POJ2239 Selecting Courses【二部图最大匹配】
主题链接: http://poj.org/problem?id=2239 题目大意: 学校总共同拥有N门课程,而且学校规定每天上12节可,一周上7天. 给你每门课每周上的次数,和哪一天哪一节 课上的. ...
- POJ1274_The Perfect Stall(二部图最大匹配)
解决报告 http://blog.csdn.net/juncoder/article/details/38136193 id=1274">题目传送门 题意: n头m个机器,求最大匹配. ...
- HDU 3729 I'm Telling the Truth(二部图最大匹配+结果输出)
职务地址:HDU 3729 二分图最大匹配+按字典序输出结果. 仅仅要从数字大的開始匹配就能够保证字典序最大了.群里有人问. . 就顺手写了这题. . 代码例如以下: #include <ios ...
- 【网络流量-二部图最大匹配】poj3041Asteroids
/* 这个问题将是每行一个x作为节点x,没有列y作为节点y,障碍物的坐标xy来自x至y的 边缘.图建的问题后,变成,拿得最少的点,因此,所有这些点与相邻边缘,即最小 点覆盖,与匈牙利算法来解决. -- ...
- (转)POJ题目分类
初期:一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. (4)递推. ...
- poj分类
初期: 一.基本算法: (1)枚举. (poj1753,poj2965) (2)贪心(poj1328,poj2109,poj2586) (3)递归和分治法. ( ...
- 转载 ACM训练计划
leetcode代码 利用堆栈:http://oj.leetcode.com/problems/evaluate-reverse-polish-notation/http://oj.leetcode. ...
- HDU5090--Game with Pearls 二分图匹配 (匈牙利算法)
题意:给N个容器,每个容器里有一定数目的珍珠,现在Jerry开始在管子上面再放一些珍珠,放上的珍珠数必须是K的倍数,可以不放.最后将容器排序,如果可以做到第i个容器上面有i个珍珠,则Jerry胜出,反 ...
随机推荐
- 用jsp写注冊页面
包含单选框.多选框.session的应用,页面自己主动跳转,中文乱码的处理,入门级 对于中文乱码的处理,注意几点:注冊页面数据提交方式为post不能忘了写,页面编码方式为gbk,处理提交信息的doRe ...
- leetcode回文子串拆分-最小拆分次数
转载请注明来自souldak,微博:@evagle 上一篇是要输出所有的可能拆分,这回是要输出拆分次数最少的切割次数. 如果直接按照上一篇那么做的话,就会超时,因为我们在判断s[i][j]是否是回文的 ...
- 【机器学习实验】学习Python来分类现实世界的数据
引入 一个机器能够依据照片来辨别鲜花的品种吗?在机器学习角度,这事实上是一个分类问题.即机器依据不同品种鲜花的数据进行学习.使其能够对未标记的測试图片数据进行分类. 这一小节.我们还是从scikit- ...
- 【iOS开发-71】解决方式:Attempting to badge the application icon but haven't received permission from the...
(1)原因 一切都是iOS8捣的鬼.您假设把模拟器换成iOS7.1或者更早的,就不会有这个问题.而如今在iOS8中要实现badge.alert和sound等都需要用户允许才干,由于这些都算做Notif ...
- 折扣&折让-看清实质的思考
折扣&折让 看清实质的思考 Author:zfive5(zidong) Email:zfive5@163.com 引子 有些东西,在没有人指点的情况,一时理解不了,就放一放,等到某一个契机到来 ...
- POJ-1324-Holedox Moving(BFS)
Description During winter, the most hungry and severe time, Holedox sleeps in its lair. When spring ...
- POJ 2151 Check the difficulty of problems (动态规划-可能DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- (7)基于hadoop的简单网盘应用实现3
一.login.jsp登陆界面实现 解压bootmetro-master.zip,然后将\bootmetro-master\src\下的assets目录复制到project里. bootmetro下载 ...
- 字典实体类:DictionaryEntry类
DictionaryEntry类是一个字典集合,主要包括的内容是键/值对.这样的组合方式能够方便地定位数据,当中的"键"具备唯一性,类似于数据库中的"id",一 ...
- 用JS实现发邮件的功能 完美解决
怎样用JS实现发邮件的功能? 我想用JS实现把页面文本框中的内容直接通过邮件的方式发送到一个指定的邮箱.fengxq给出的答案是<script language=javascript>if ...