poj Selecting Courses
来源:互联网 发布:疯狂软件 编辑:程序博客网 时间:2024/05/08 14:40
把课程和对应的课来做最大二分匹配,一天有12节课,map[c][(p-1)*12+q]即把课程与对应的课存进去了,然后就是最大二分匹配了
#include<iostream>#include<algorithm>#include<string.h>#include<stack>#include<queue>#include<math.h>#include<cstdio>using namespace std;int map[310][310];int match[310];bool vis[310];int n,m;bool dfs(int u){for(int i=1;i<=m;i++){if(!vis[i] && map[u][i]){vis[i]=1;if(match[i]==-1 || dfs(match[i])){match[i]=u;return true;}}}return false;}int Match(){int sum=0;for(int i=0;i<n;i++){memset(vis,0,sizeof(vis));if(dfs(i))sum++;}return sum;}int main(){int c,p,q;while(~scanf("%d",&n)){memset(map,0,sizeof(map));memset(match,-1,sizeof(match));m=12*7;for(int i=0;i<n;i++){scanf("%d",&c);while(c--){scanf("%d%d",&p,&q);map[i][(p-1)*12+q]=1;}}printf("%d\n",Match());}return 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 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 G - Selecting Courses
- POJ 2239 Selecting Courses (二分匹配)
- 创建型模式之建造者(Builder)模式
- Cocos2D-X Tutorial for iOS and Android: Getting Started
- AES加密进行Android的SharedPreferences存储
- 黑马程序员---泛型
- Hadoop和HBase集群的JMX监控
- poj Selecting Courses
- C++ 函数模板与类模板
- PopUpWindow 位置分析
- Debian系统下利用vsdftpd+Mysql实现虚拟用户登录(Debian+vsftpd+Mysql)
- Linux下MyEclipse不能输入中文的解决方法
- Suspend&Resume流程
- 程序员必知算法----BM字符串查找算法
- 【Windows7系统装什么浏览器好用】
- 修改(自定义)窗口的标题栏和图标