Courses

Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 5214    Accepted Submission(s): 2502

Problem 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

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:

 
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<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#define mem(x,y) memset(x,y,sizeof(x))
using namespace std;
const int INF=0x3f3f3f3f;
const int MAXN=;
vector<int>vec[MAXN];
int usd[MAXN],vis[MAXN];
bool dfs(int x){
for(int i=;i<vec[x].size();i++){
int v=vec[x][i];
if(!vis[v]){
vis[v]=;
if(!usd[v]||dfs(usd[v])){
usd[v]=x;return true;
}
}
}
return false;
}
int main(){
int T,P,N,t,a;
scanf("%d",&T);
while(T--){
mem(usd,);
mem(vis,);
for(int i=;i<MAXN;i++)vec[i].clear();
scanf("%d%d",&P,&N);
for(int i=;i<=P;i++){
scanf("%d",&t);
while(t--){
scanf("%d",&a);
vec[i].push_back(a);
}
}
int ans=;
for(int i=;i<=P;i++){
mem(vis,);
if(dfs(i))ans++;
}
if(ans==P)puts("YES");//应该是等于P的
else puts("NO");
}
return ;
}

Courses(最大匹配)的更多相关文章

  1. hdu 1083 Courses (最大匹配)

    CoursesTime Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total Su ...

  2. poj图论解题报告索引

    最短路径: poj1125 - Stockbroker Grapevine(多源最短路径,floyd) poj1502 - MPI Maelstrom(单源最短路径,dijkstra,bellman- ...

  3. HDU1083 Courses —— 二分图最大匹配

    题目链接:https://vjudge.net/problem/HDU-1083 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory ...

  4. POJ1469 COURSES 【二分图最大匹配&#183;HK算法】

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17777   Accepted: 7007 Descript ...

  5. POJ2239 Selecting Courses(二分图最大匹配)

    题目链接 N节课,每节课在一个星期中的某一节,求最多能选几节课 好吧,想了半天没想出来,最后看了题解是二分图最大匹配,好弱 建图: 每节课 与 时间有一条边 #include <iostream ...

  6. HDU-----(1083)Courses(最大匹配)

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  7. [POJ] 2239 Selecting Courses(二分图最大匹配)

    题目地址:http://poj.org/problem?id=2239 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...

  8. POJ2239_Selecting Courses(二分图最大匹配)

    解题报告 http://blog.csdn.net/juncoder/article/details/38154699 题目传送门 题意: 每天有12节课.一周上7天,一门课在一周有多天上课. 求一周 ...

  9. POJ2239 Selecting Courses【二部图最大匹配】

    主题链接: http://poj.org/problem?id=2239 题目大意: 学校总共同拥有N门课程,而且学校规定每天上12节可,一周上7天. 给你每门课每周上的次数,和哪一天哪一节 课上的. ...

随机推荐

  1. Unity cg vertex and fragment shaders(一)

    cg片段 Cg程序片段写CGPROGRAM和ENDCG之间 开始时的片段可以作为#pragma语句编译指令 Pass { // ... the usual pass state setup ... C ...

  2. IS-A 和 HAS-A

    IS-A关系 IS-A就是说:一个对象是另一个对象的一个分类. 下面是使用关键字extends实现继承. public class Animal{ } public class Mammal exte ...

  3. POJ 3268 Silver Cow Party 正反图最短路

    题目:click here 题意: 给出n个点和m条边,接着是m条边,代表从牛a到牛b需要花费c时间,现在所有牛要到牛x那里去参加聚会,并且所有牛参加聚会后还要回来,给你牛x,除了牛x之外的牛,他们都 ...

  4. js限制图片的大小

    <form id="financialForm" action="<%=basePath%>riskcontrol/website/review_bor ...

  5. pexpect-pxssh-登陆Linux-执行命令

    #!/usr/bin/python import pexpect import pxssh try: remote=pxssh.pxssh() hostname=raw_input('hostname ...

  6. 斯坦福 IOS讲义 课件总结 一

    1,引入文件, #import <Foundation/Foundation.h> IOS7 中可以这样写 @import Foundation; 2,在.h文件引入的是公用的,在.m文件 ...

  7. 二代USBKEY与一代USBKEY有什么区别?使用时需要注意什么?

    二代USBKEY相较于一代USBKEY产品,增加了屏幕以及按键功能:可通过二代USBKEY产品的屏幕查看交易或操作信息,通过按键的方式进行上翻.下翻.确认.取消等操作. 二代USBKEY产品采用Mic ...

  8. MFC消息截获之pretranslatemessage

    前几天,查了一个batch的问题,问题大致是这样,父窗口消息一个鼠标消息,弹出一个模态框,CPU负荷就飚升到100%(双核就是50%),非常怪异,用windbg,分析哪个线程占用CPU,定位到鼠标响应 ...

  9. Binary Tree Level Order Traversal II --leetcode C++

    考察点 广度优先遍历--层次遍历 STL内容器的用法 广度优先遍历的时候,首先应该想到的就是借助于队列.还需要在遍历下一层之前保存当前层节点的数量 代码很简单: class Solution { pu ...

  10. Parsing HTML with C++ (using Qt preferably) - Stack Overflow

    Parsing HTML with C++ (using Qt preferably) - Stack Overflow Parsing HTML with C++ (using Qt prefera ...