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 ...
随机推荐
- validate
<?php $rules = [ "ip" => function ($var) {return ip2long($var);}, "email" ...
- Python图表绘制:matplotlib绘图库入门
matplotlib 是Python最著名的绘图库,它提供了一整套和matlab相似的命令API,十分适合交互式地行制图.而且也可以方便地将它作为绘图控件,嵌入GUI应用程序中. 它的文档相当完备,并 ...
- datalist的用法
DataList 提供相关的编辑模板,但和DataGrid不一样的是,DataList没有编辑按钮.要在DataList中使用编辑功能,可在项模板中增加一个按 钮,Linkbutton和Button都 ...
- hadoop实战之分布式模式
环境 192.168.1.101 host101 192.168.1.102 host102 1.安装配置host101 [root@host101 ~]# cat /etc/hosts |grep ...
- php 二维数组(没啥技术含量)
<?php $cars = array( array('benchi',20,18), array('baoma',30,21), array('aodi',23,9) ); echo $car ...
- 用C#开发了四天的UWP应用有感
第一个就是异步方法,async-await,所谓async关键字,并没有什么实际上的语法意义,只是写在函数签名的位置让编译器方便进行查找以及静态检查,并且提醒程序员这是一个异步方法而已.至于await ...
- tensorflow 学习1 环境搭建
1. 下载Anaconda(首选官网,但很慢) Anaconda2-4.0.0-Linux-x86_64.sh Anaconda 安装包还可以到 https://mirrors.tuna.tsingh ...
- PHP连接SQLServer
连接前配置系统: 1.检查文件 php5.2.5/ntwdblib.dll 默认下面有一个,不能连接再替换. 下载正确版本的 ntwdblib.dll (2000.80.194.0),地址: http ...
- Lighttpd虚拟主机和多域名的配置
lighttpd是个轻巧的web服务器组件,在linux系统上较为流行,功能能满足一般网站的需求(虚拟主机,伪静态,防盗链等),而跑起来负载却低于apache. 一般网站地址的形式为www.xxx.c ...
- win10内网外网智能访问
当电脑同时连接有线和WiFi时(有线连接为内网,WiFi为外网),会出现内网和外网内容无法同时访问的情况. 本方法实现内网和外网的同时访问. 第一步: 输入指令 “route print ” 查看路由 ...