POJ 2239
#include<iostream>
#include<algorithm>
#define MAXN 305
using namespace std; int _m[MAXN][MAXN];
int time[][];
int match[MAXN];
bool ck[MAXN]; bool search(int a,int b,int x)
{
int i;
int t;
for ( i = ; i < b ; i++)
if (_m[x][i] && ! ck[i])
{
ck[i] = true;
t = match[i];
match[i] = x;
if (t == - || search(a,b,t))
return true;
match[i] = t;
}
return false;
} int hungary(int a,int b)
{
memset(match,-,sizeof(match));
int max_match = ;
int i;
for ( i = ; i < a ; i++)
{
memset(ck,false,sizeof(ck));
if (search(a,b,i))
max_match++;
}
return max_match;
} int main()
{
//freopen("acm.acm","r",stdin);
int n;
int num;
int i;
int j;
int u;
int v;
int k;
int node_num = ;
while(cin>>n)
{
node_num = ;
memset(_m,,sizeof(_m) );
memset(time,-,sizeof(time));
for(k = ; k < n; ++ k)
{
cin>>num;
for(i = ; i < num; ++ i)
{
cin>>u>>v;
-- u;
-- v;
if(time[u][v] == -)
{
time[u][v] = node_num ++;
_m[k][time[u][v]] = ;
}
else
{
_m[k][time[u][v]] = ;
}
}
}
cout<<hungary(n,node_num)<<endl;
} }
关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com
POJ 2239的更多相关文章
- poj 2239 二分图最大匹配,基础题
1.poj 2239 Selecting Courses 二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...
- 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 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...
- [POJ] 2239 Selecting Courses(二分图最大匹配)
题目地址:http://poj.org/problem?id=2239 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 2239 Selecting Courses
二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...
- Selecting Courses POJ - 2239(我是沙雕吧 按时间点建边 || 匹配水题)
呃呃呃呃呃 把每个课给了INF个容量....我是沙雕把....emm....这题就是做着玩...呃呃呃别当真.... #include <iostream> #include <cs ...
- POJ 2239 匈牙利算法
思路:最大匹配 也是很裸的一道题-. // by SiriusRen #include <cstdio> #include <cstring> #include <alg ...
- POJ 2239:Selecting Courses 选课
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9380 Accepted: 4177 ...
随机推荐
- Redis多API开发实践
一.Redis API支持 Redis提供了各类开发语言的API,方便开发语言连接使用Redis. https://redis.io/clients 官方网站提供了不同开发语言的API程序. Pyth ...
- Makefiles in Linux
http://www.codeproject.com/Articles/31488/Makefiles-in-Linux-An-Overview
- An Introduction To Value at Risk (VAR)
http://www.investopedia.com/articles/04/092904.asp http://www.jpmorgan.com/tss/General/email/1159360 ...
- Linux CentOS6 mysql rpm安装
mysql rpm文件下载地址:https://dev.mysql.com/downloads/mysql/ 选择操作系统及版本: 点击5.6版本链接 将下载好的文件上传至服务器 下面开始安装: 检查 ...
- Java 设计模式系列(十八)备忘录模式(Memento)
Java 设计模式系列(十八)备忘录模式(Memento) 备忘录模式又叫做快照模式(Snapshot Pattern)或Token模式,是对象的行为模式.备忘录对象是一个用来存储另外一个对象内部状态 ...
- 关于流程图设计,你需要Get的几点必备知识
流程图(Flow Chart)这个概念对很多人来说并不陌生,但如果让你定义或者举例说明什么是产品流程图,恐怕还是有难度的.或许诸如“用户体验”.“交互设计”.“逻辑关系”等词会像走马灯般闪现在你的脑海 ...
- Composer安装和使用 - Windows
记录windows下安装和使用Composer的方法 1,使用安装程序 这是将 Composer 安装在你机器上的最简单的方法. 下载并且运行 Composer-Setup.exe,它将安装最新版本的 ...
- Ural 1519 Formula 1 (DP)
题意:给定一个 n * m 的矩阵,问你能花出多少条回路. #pragma comment(linker, "/STACK:1024000000,1024000000") #inc ...
- 一款好用的js插件及工具包
笔记:需要源码私信 script文件夹 script下的目录文件: 使用的效果,解决ie兼容性问题,好处多多!慢慢参考! 具体用法: 前端引入js,写必须要的js脚本! <script src= ...
- ServiceStack.Text json中序列化日期格式问题的解决
标记: ServiceStack.Text,json,序列化,日期 在使用ServiceStack.Text的序列化为json格式的时候,当属性为datetime的时候,返回的是一个new date( ...