poj2239 Selecting Courses解题报告
来源:互联网 发布:大数据应用是什么 编辑:程序博客网 时间:2024/06/06 19:15
题目意思:
一天12节课,一个星期七天。有n中课程,每种课程只要上m[i]节课的一节就可以了,求最多能上多少节课?
解题思路:这是一道典型的求二分图的最大匹配问题,用匈牙利算法解决。
代码:
#include<iostream>
using namespace std;
int a[500][100],match[500],n,m=84,che[500];
int dfs(int k)
{
int i,t;
for(i=1;i<=m;i++)
{
if(!che[i]&&a[k][i])
{
t=match[i];match[i]=k;che[i]=1;
if(t==-1||dfs(t)) return 1;
match[i]=t;
}
}
return 0;
}
int maxflow()
{
int i,ans=0;
for(i=1;i<=n;i++)
{
memset(che,0,sizeof(che));
if(dfs(i)) ans++;
}
return ans;
}
int main()
{
int i,j,k,d,c;
while(cin>>n)
{
memset(a,0,sizeof(a));
memset(match,-1,sizeof(match));
for(i=1;i<=n;i++)
{
cin>>k;
for(j=0;j<k;j++)
{
cin>>d>>c;
a[i][(d-1)*12+c]=1;
}
}
cout<<maxflow()<<endl;
}
return 0;
}
- poj2239 Selecting Courses解题报告
- poj2239 - Selecting Courses
- poj2239 Selecting Courses
- POJ2239:Selecting Courses
- POJ2239 Selecting Courses(二分图)
- poj2239-Selecting Courses(匈牙利算法)
- poj2239 Selecting Courses --- 二分图最大匹配
- POJ2239 Selecting Courses【二分图最大匹配】
- poj2239 Selecting Courses(最大二分图匹配 (匈牙利算法) 实现 )
- poj2239——Selecting Courses(二分图匹配)
- POJ2239 Selecting Courses(二分图匹配,匈牙利算法)
- POJ 2239 Selecting Courses(二分图匹配——匈牙利算法||网络流)解题报告
- Pku acm 2239 Selecting Courses 数据结构题目解题报告(十二)---- 匈牙利算法求二分图的最大匹配
- POJ-1469-COURSES 解题报告
- PKU_2239 Selecting Courses
- pku2239 Selecting Courses
- POJ 2239 Selecting Courses
- poj 2239 Selecting Courses
- (30)PHP中函数的使用(下)(31)数据的概述及分类与声明
- Cannot get a connection, pool exhausted
- 想成为软件架构师的人都应该明白的事情
- Tomcat的配置
- Android开发中定时器的3种方法
- poj2239 Selecting Courses解题报告
- Qt中事件处理的方法
- 【Hibernate】入门搭建之Annotation
- Android入门:向TextView添加滚动条
- 台湾英语语法视频
- java 内存配置
- Android 中消息处理机制-Looper、Handler、Thread (二)
- mysql-5.0.45 安装
- ORA-01102: cannot mount database in EXCLUSIVE mode