poj 2239 Selecting Courses (二分匹配)
Time Limit: 1000MS | Memory Limit: 65536K | |
Total Submissions: 8316 | Accepted: 3687 |
Description
There are 12 classes every day, and 7 days every week. There are hundreds of courses in the college, and teaching a course needs one class each week. To give students more convenience, though teaching a course needs only one class, a course will be taught several times in a week. For example, a course may be taught both at the 7-th class on Tuesday and 12-th class on Wednesday, you should assume that there is no difference between the two classes, and that students can select any class to go. At the different weeks, a student can even go to different class as his wish. Because there are so many courses in the college, selecting courses is not an easy job for Li Ming. As his good friends, can you help him?
Input
Output
Sample Input
5
1 1 1
2 1 1 2 2
1 2 2
2 3 2 3 3
1 3 3
Sample Output
4
Source
//224K 32MS C++ 1154B 2014-06-08 09:36:09
//构图思想很重要..
#include<iostream>
#include<vector>
#define N 105
using namespace std;
int p[N];
vector<int>V[*N];
int match[N];
int vis[N];
int n;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int m,a,b;
while(scanf("%d",&n)!=EOF)
{
memset(p,,sizeof(p));
for(int i=;i<=n;i++) V[i].clear();
memset(p,,sizeof(p));
int pos=;
for(int i=;i<n;i++){
scanf("%d",&m);
for(int j=;j<m;j++){
scanf("%d%d",&a,&b);
if(!p[(a-)*+b])
p[(a-)*+b]=++pos;
V[i].push_back(p[(a-)*+b]);
}
}
printf("%d\n",hungary());
}
return ;
}
poj 2239 Selecting Courses (二分匹配)的更多相关文章
- poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- [POJ] 2239 Selecting Courses(二分图最大匹配)
题目地址:http://poj.org/problem?id=2239 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...
- POJ 2239 Selecting Courses
二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...
- POJ 1469(裸二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18993 Accepted: 7486 Descript ...
- poj 3057(bfs+二分匹配)
题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区 ...
- poj 1469 COURSES (二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16877 Accepted: 6627 Descript ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
- poj 2584 T-Shirt Gumbo (二分匹配)
T-Shirt Gumbo Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 2571 Accepted: 1202 Des ...
随机推荐
- 在Linux系统中如何设置APACHE服务器里的后台页面只允许某个IP地址访问
补充资料 本网络中使用LINUX服务器,web服务器是由APACHE搭建,IP地址为192.168.1.5,后台页面为/admin/login.jsp . 如何设置后台页面LOGIN.JSP只允许19 ...
- Unity3D研究院之获取摄像机的视口区域
摄像机分为两种,一种是正交摄像机还有一种是透视摄像机.正交摄像机无论远近它的视口范围永远是固定的,但是透视摄像机是由原点向外扩散性发射,也就是距离越远它的视口区域也就越大.那么我们如何获取距离摄像机任 ...
- Android学习二:Http操作
1.初步认识HTTP HTTP(Hypertext Transfer Protocol超文本传输协议)是网络应用层协议,建立在TCP/IP基础上,HTTP使用可靠的TCP连接,默认端口是80. 较常用 ...
- nunjucks.js模板渲染
直接用 script 引入文件: <script src="nunjucks.js"></script> 是使用 render 来直接渲染文件,这种方式支持 ...
- 重定向 url cookie
想象下面两行伪代码: 1. setCookie(...);2. redirect(new_web_url); 首先设置一个Cookie,然后重定向到另外一个网址,这个网址跟当前网站的域名不同 在多数情 ...
- mac osx 快捷键符号以及意义 触发角:锁屏
快捷键中常用符号⌘(command).⌥(option).⇧(shift).⇪(caps lock).⌃(control).↩(return).⌅(enter). OSX快捷键 快捷键中常用符号 ⌘( ...
- AS2使用ExternalInterface
以下代码是帧脚本(选中某帧F9,粘贴) import flash.external.ExternalInterface; // 假的,目的是为了执行createButton里面的ExternalInt ...
- 调Windows 7的图片浏览器查看图片
public static void viewPicFromWindows(string pPicPath) { if (pPicPath!="" && Syste ...
- [solr] - Facet
Solr facet使用于分类统计,是最好的工具.下面例子使用facet将可模拟查询搜索出租房信息. 1.在schema.xml中的内容如下: <?xml version="1.0&q ...
- php命令传参
1.url方式 $param = array(); if ($argc > 1) { parse_str ( $argv [1], $param ); foreach ( $param as $ ...