POJ 1469:COURSES
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 19458 | Accepted: 7658 |
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
选课。给了每一门课有那些学生选。要问的是在给定的关系的情况下,能不能求出一个学生集合,这个集合里面能够满足这样的关系:
1.每门课都能派出一个学生代表。
2.每个学生都代表了一门课。
不能更匈牙利了。
代码:
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <cstring>
#pragma warning(disable:4996)
using namespace std; int grid[305][305];
int link[305];
int visit[305];
int n,k,V1,V2;
int result; bool dfs(int x)
{
int i;
for(i=1;i<=V2;i++)
{
if(grid[x][i]==1&&visit[i]==0)
{
visit[i]=1;
if(link[i]==-1||dfs(link[i]))
{
link[i]=x;
return true;
}
}
}
return false;
} bool Magyarors()
{
int i; result=0;
memset(link,-1,sizeof(link));//!!这里不能是0 for(i=1;i<=V1;i++)
{
memset(visit,0,sizeof(visit));
if(!dfs(i))
{
return false;
}
}
return true;
} int main()
{
int Test,i,j,num,temp;
cin>>Test; while(Test--)
{
memset(grid,0,sizeof(grid));
cin>>V1>>V2; for(i=1;i<=V1;i++)
{
scanf("%d",&num);
for(j=1;j<=num;j++)
{
scanf("%d",&temp);
grid[i][temp]=1;
}
}
if(V1>V2)
{
cout<<"NO"<<endl;
}
else
{
if(Magyarors())
{
cout<<"YES"<<endl;
}
else
{
cout<<"NO"<<endl;
}
}
}
return 0;
}
版权声明:本文为博主原创文章,未经博主允许不得转载。
POJ 1469:COURSES的更多相关文章
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- POJ 3321:Apple Tree + HDU 3887:Counting Offspring(DFS序+树状数组)
http://poj.org/problem?id=3321 http://acm.hdu.edu.cn/showproblem.php?pid=3887 POJ 3321: 题意:给出一棵根节点为1 ...
- POJ 3252:Round Numbers
POJ 3252:Round Numbers Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 10099 Accepted: 36 ...
- 二分图匹配 最大匹配数+最大点覆盖 POJ 1469+POJ 3041
最大匹配数就等于最大点覆盖,因为在图里面,凡是要覆盖的点必定是连通的,而最大匹配之后,若还有点没有覆盖到,则必定有新的匹配,与最大匹配数矛盾,如果去掉一些匹配,则必定有点没有覆盖到. POJ 1469 ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
- HDU - 1083 Courses /POJ - 1469
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1083 http://poj.org/problem?id=1469 题意:给你P个课程,并且给出每个课 ...
- poj 1469 COURSES 解题报告
题目链接:http://poj.org/problem?id=1469 题目意思:有 N 个人,P个课程,每一个课程有一些学生参加(0个.1个或多个参加).问 能否使得 P 个课程 恰好与 P 个学生 ...
- POJ 1469 COURSES 二分图最大匹配 二分图
http://poj.org/problem?id=1469 这道题我绝壁写过但是以前没有mark过二分图最大匹配的代码mark一下. 匈牙利 O(mn) #include<cstdio> ...
随机推荐
- vCenter 导入Windows Server 2003/XP自定义规范失败
1.vcsa 切换到/etc/vmware-vpx/sysprep目录下,会有很多个目录,根据Windows Server 2003的版本,64位找到 svr2003-64 这个目录,32位找到svr ...
- Program-Language
1. 主流编程语言 2. 编程语言分类 2.1 编译or解释 2.2 按照客观系统的描述可分为两类 2.3 按照编程范型可分为 3. 语言范式 Paradigm 4. 计算机语 ...
- 我的第一个爬虫【python selenium】
去年写的一个小功能,一年过得好快,好快! 目的:爬取京东商品详情页面的内容(商品名称.价格.评价数量)后存储到xls文档中,方便商家分析自己商品的动态. 软件:chrome(windows).chro ...
- Tcp 3次握手 4次挥手
Tcp 3次握手 4次挥手 标签(空格分隔): Java基础 报文介绍: SYN(synchronous建立联机) ACK(acknowledgement 确认) FIN(finish结束) PSH( ...
- ②初识spring
一:基础搭建 需要:eclipse.spring插件(确认版本号并下载对应插件详见:https://blog.csdn.net/a1150499208/article/details/87988392 ...
- delphi的dbgrid控件点击title排序
procedure TfrmMain.DBGridEhTitleClick(Column: TColumnEh);var i : integer;begin for i:= 1 to DBGridEh ...
- thinkphp配置到二级目录,不配置到根目录,访问除首页的其他路径都是404报错
1.在nginx的配置里面,进行重定向 vi /etc/nginx/conf.d/default.conf 2.进入编辑 location /thinkphp/public { if (!-e $re ...
- HDU - 1394 Minimum Inversion Number(线段树求逆序数---点修改)
题意:给定一个序列,求分别将前m个数移到序列最后所得到的序列中,最小的逆序数. 分析:m范围为1~n,可得n个序列,求n个序列中最小的逆序数. 1.将序列从头到尾扫一遍,用query求每个数字之前有多 ...
- 完全卸载(删除)mac下自带的php
/private/etc sudo rm -rf php-fpm.conf.defaultphp.ini php.ini.default /usr/bin sudo rm -rf php php-co ...
- CSS - 强制换行和禁止换行强制换行 和禁止换行样
强制换行 word-break: break-all; 只对英文起作用,以字母作为换行依据. word-wrap: break-word; 只对英文起作用,以单词作为换行依据. whi ...