POJ 2239 Selecting Courses(二分图最大匹配)
来源:互联网 发布:黑龙江省人工智能学会 编辑:程序博客网 时间:2024/05/22 12:05
题意:小明需要去选择课程,他是一个爱学习的人,所以想尽可能多的选择课程,学校里有n个课程,并且在学校规定,每周里的每天有12节课,那么一周就有7*12节课。如果几个课程都在那d天的那c节课上课,那么你需要选择其中的一个,而不能选择多个课程现在要求算出小明最多可以选择多少个课程上.
思路:左边的点表示课程,右边的点表示7*12=84个时间段,那么显然就是二分图最大匹配问题
#include<cstdio>#include<cstring>#include<vector>using namespace std;const int maxn=1000;struct Max_Match{ int n,m; vector<int> g[maxn]; bool vis[maxn]; int left[maxn]; void init(int n,int m) { this->n=n; this->m=m; for(int i=1;i<=n;i++) g[i].clear(); memset(left,-1,sizeof(left)); } bool match(int u) { for(int i=0;i<g[u].size();i++) { int v=g[u][i]; if(!vis[v]) { vis[v]=true; if(left[v]==-1 || match(left[v])) { left[v]=u; return true; } } } return false; } int solve() { int ans=0; for(int i=1;i<=n;i++) { memset(vis,0,sizeof(vis)); if(match(i)) ans++; } return ans; }}MM;int T;int main(){int n;while (scanf("%d",&n)!=EOF){MM.init(n,84);for (int i = 1;i<=n;i++){int m;scanf("%d",&m);while (m--){int p,q;scanf("%d%d",&p,&q);MM.g[i].push_back((p-1)*12+q);}}printf("%d\n",MM.solve());} return 0;}
0 0
- poj 2239 Selecting Courses 二分图最大匹配数
- poj 2239 Selecting Courses 二分图最大匹配
- Poj 2239 Selecting Courses 二分图最大匹配
- POJ 2239 Selecting Courses(二分图最大匹配)
- POJ 2239 Selecting Courses(二分图最大匹配)
- poj 2239 Selecting Courses 二分图最大匹配
- POJ 2239-Selecting Courses(二分图_最大匹配+哈希建图)
- poj 2239 Selecting Courses 【二分图最大匹配】
- POJ - 2239 Selecting Courses 二分图 最大匹配
- POJ 2239--Selecting Courses【二分图 && 最大匹配数 && 水题】
- POJ 2239 Selecting Courses(二分图最大匹配)
- poj Selecting Courses 2239 (二分图最大匹配)
- POJ 2239 Selecting Courses(二分图最大匹配)
- POJ-2239 Selecting Courses(二分图最大匹配)
- POJ 2239 - Selecting Courses(二分图匹配)
- poj Selecting Courses(二分图最大匹配)
- POJ 2239Selecting Courses(二分图最大匹配之最大匹配)
- poj 2239 Selecting Courses(二分图最大匹配or最大流)
- 虽鸡汤,但够补
- uvaoj-401:回文词
- 查看Eclipse版本号,及各个版本区别
- 蓝桥杯 历届试题 错误票据
- Ubuntu14.04 下apt-get安装Code::Blocks
- POJ 2239 Selecting Courses(二分图最大匹配)
- 多人聊天室
- 算法学社 -- "这是一道难题"第一期
- 《VMWARE核心技术网卡三种模式》
- POJ 3468_A Simple Problem with Integers(树状数组)
- Android屏幕适配全攻略
- 2016蓝桥杯算法训练——出现次数最多的整数
- bzoj1831【AHOI2008】逆序对
- 安卓总结 Activity生命周期