题目链接:http://poj.org/problem?id=1469

COURSES
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 21229   Accepted: 8355

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

Input

Your
program should read sets of data from the std input. The first line of
the input 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抣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

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.

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

 
题意:

给你p门课程和n个学生,一个学生可以选0门,1门,或者多门课程,现在要求一个由p个学生组成的集合,满足下列2个条件:

1.每个学生选择一个不同的课程

2.每个课程都有不同的代表

如果满足,就输出YES

分析:

做最大匹配,要是匹配数是P就是YES.

#include <stdio.h>
#include <string.h> int p,n;
bool maps[][];
bool use[];
int match[]; bool DFS(int u)
{
for(int i=; i<=n; i++)
{
if(!use[i]&&maps[u][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(match,-,sizeof(match));
memset(maps,false,sizeof(maps));
scanf("%d%d",&p,&n);
int num = ;
for(int i=; i<=p; i++)
{
int stu;
scanf("%d",&stu);
for(int j=; j<=stu; j++)
{
int v;
scanf("%d",&v);
maps[i][v] = true;
}
} for(int i=; i<=p; i++)
{ memset(use,false,sizeof(use));
if(DFS(i))
num++;
}
if(num==p)
printf("YES\n");
else printf("NO\n"); } return ;
}

Poj(1469),二分图最大匹配的更多相关文章

  1. poj 1469 二分图最大匹配

    就是最简单的最大匹配,没的说 #include<iostream> #include<cstdio> #include<cstring> #include<a ...

  2. poj 1469(二分图 最大匹配)

    这道题让我认识到了c++cin,cout确实会使其超时,还是我用的c printf吧 #include<cstdio> #include<iostream> #include& ...

  3. poj 2239 二分图最大匹配,基础题

    1.poj 2239   Selecting Courses   二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...

  4. POJ 2226二分图最大匹配

    匈牙利算法是由匈牙利数学家Edmonds于1965年提出,因而得名.匈牙利算法是基于Hall定理中充分性证明的思想,它是二部图匹配最常见的算法,该算法的核心就是寻找增广路径,它是一种用增广路径求二分图 ...

  5. POJ Evacuation /// 二分图最大匹配

    题目大意: 在一个n*m的房间中 ‘X’为墙 ‘D’为门 ‘.’为人 门只存在与外围 人每秒钟只能向四连通区域走一步 门比较狭窄 每秒钟只能通过一个人 求所有人逃脱的最短时间 如果不可能则输出impo ...

  6. poj 2724 二分图最大匹配

    题意: 会给出M个串,我们要做的就是将这M个串给清除了.对于任意两个串,若二进制形式只有一位不一样,那么这两个串可以在一次操作消除,否则每个操作只能消除一个串. 3 3 *01 100 011 可以代 ...

  7. Asteroids - poj 3041(二分图最大匹配问题)

      Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 17258   Accepted: 9386 Description Be ...

  8. poj 2446 二分图最大匹配

    思路:由(i+j)为偶数的点向(i+j)为奇数的点建边.求一次最大匹配,若正好为空格数(不包含洞)的一半,即输出YES. #include<iostream> #include<cs ...

  9. POJ 1719 二分图最大匹配(记录路径)

    Shooting Contest Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4097   Accepted: 1499 ...

  10. poj 3692 二分图最大匹配

    思路: 如果我们将认识的建边,求最大独立集就是互相不认识的人数.那么我们反过来,将不认识的建图,求最大独立集就是互相认识的人数. #include<cstdio> #include< ...

随机推荐

  1. Swift实战-小QQ(第2章):QQ侧滑菜单

    QQ侧滑实现架构:需要建立以下几个ViewController:1.XQBaseViewController 2.LeftViewController3.RightViewController4.Co ...

  2. Python和Ruby开发中源文件中文注释乱码的解决方法(Eclipse和Aptana Studio3均适用)

    Eclipse的设置(Aptana Studio3与Eclipse基本完全相同,此处略) window->preferences->general->editors->text ...

  3. (二)重拾单片机 第一天 LED灯

    由图知道 低电平 亮,高电平 灭 控制第一个 LED1 亮灭程序代码,如下 #include<reg52.h> #define uchar8 unsigned char #define u ...

  4. 夺命雷公狗---2016-linux---2之软件实现远程登录

    废话不多说,操作方法如下所示:

  5. 夺命雷公狗---微信开发55----微信js-sdk接口开发(2)接口功能介绍之签名算法

    我们JS-SDK里面其实有不少的接口 startRecord---录音 stopRecord---停止录音 playVoice---播放 pauseVoice---暂停播放 uploadImage-- ...

  6. QTP常用功能

    1.QTP录制过程的截图 查看录制脚本过程中QTP的截图可以在QTP中查找,在关键字视图中点击每一步都对应一个截图   2.在关键字视图中为测试步骤添加注释 在关键字视图中表格列头中单击鼠标右键,选择 ...

  7. 基于mjpg_streamer视频服务器移植【转】

    本文转载自:http://blog.csdn.net/wavemcu/article/details/7539560 MJPG简介: MJPG是MJPEG的缩写,但是MJPEG还可以表示文件格式扩展名 ...

  8. kvm虚拟机virt-manager启动报错

    安装kvm,用virt-manager启动时报错如下: Traceback (most recent call last):  File "/usr/share/virt-manager/v ...

  9. JVM学习笔记(一)------基本结构【转】

    转自:http://blog.csdn.net/cutesource/article/details/5904501 版权声明:本文为博主原创文章,未经博主允许不得转载. 从Java平台的逻辑结构上来 ...

  10. 正确配置Linux系统ulimit值的方法【转】

    转自:http://www.cnblogs.com/ibook360/archive/2012/05/11/2495405.html 在Linux下面部署应用的时候,有时候会遇上Socket/File ...