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胜出,反 ... 
随机推荐
- THashMD5,THashSHA1,THashBobJenkins,TIdHashMessageDigest5的用法
			[delphi] view plain copy unit Unit1; interface uses Winapi.Windows, Winapi.Messages, System.SysUtils ... 
- linux expect, spawn用法小记
			linux expect, spawn用法小记_IT民工_百度空间 linux expect, spawn用法小记 版权声明:转载时请以超链接形式标明文章原始出处和作者信息及本声明http://sys ... 
- 黑马程序员:Java基础总结----类加载器
			黑马程序员:Java基础总结 类加载器 ASP.Net+Android+IO开发 . .Net培训 .期待与您交流! 类加载器 Java虚拟机中可以安装多个类加载器,系统默认三个主要类加载器,每个 ... 
- java中clone的深入理解
			Java中Clone的概念大家应该都很熟悉了,它可以让我们很方便的“制造”出一个对象的副本来,下面来具体看看java中的Clone机制是如何工作的? 1. Clone和Copy 假 ... 
- git digest
			.gitignore文件示例: .classpath .project .idea/ .settings/ target/ *~ *.iml *.log *.tmp https://zhuanlan. ... 
- Android开发者必须深入学习的10个应用开源项目
			Android 开发又将带来新一轮热潮,很多开发者都投入到这个浪潮中去了,创造了许许多多相当优秀的应用.其中也有许许多多的开发者提供了应用开源项 目,贡献出他们的智慧和创造力.学习开源代码是掌握技术的 ... 
- atitit.高级编程语言的特性 and 未来趋势与进化.doc
			atitit.高级编程语言的特性 and 未来趋势与进化.doc 1 编程语言的发展历程 1 1.1 编程语言的进化,起始发现背后的思想 :不论什么两个系统之间的复杂性,都能够通过加入一个抽象层要屏蔽 ... 
- liunx清理磁盘du -h --max-depth=1 /data/*
			liunx清理磁盘du -h --max-depth=1 /data/* 
- 在CodeBlocks 开发环境中配置使用OpenCV (ubuntu系统)
			CodeBlocks是一个开放源代码的全功能的跨平台C/C++集成开发环境.CodeBlocks由纯粹的C++语言开发完毕,它使用了蓍名的图形界面库wxWidgets.对于追求完美的C++程序猿,再也 ... 
- Android最方便的数据库--LitePal
			郭最近看到神分析LitePal相框,我感觉很强烈,尝试了一下,真的好,我不知道,如果你不习惯学习,那么各不相同,我觉得很合适 看完之后,思想,对于我来说,,实体到set颂值,如果数据非常多,那么你可以 ... 
