POJ 2239 Selecting Courses
二分图的最大匹配。课程和时间可以看做二分图。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; const int MAXN=;
int nx,ny;
int g[MAXN][MAXN];
int cx[MAXN],cy[MAXN];
int mk[MAXN];
int n;
int ZH[]; int path(int u)
{
for(int v=; v<ny; v++)
{
if(g[u][v]&&!mk[v])
{
mk[v]=;
if(cy[v]==-||path(cy[v]))
{
cx[u]=v;
cy[v]=u;
return ;
}
}
}
return ;
} int MaxMatch()
{
int res=;
memset(cx,-,sizeof(cx));
memset(cy,-,sizeof(cy));
for(int i=; i<nx; i++)
{
if(cx[i]==-)
{
memset(mk,,sizeof(mk));
res=res+path(i);
}
}
return res;
} int main()
{
int i,t,p,q;
while(~scanf("%d",&nx))
{
memset(g,,sizeof(g));
for(i=;i<;i++) ZH[i]=-;
ny=;
for(i=;i<nx;i++)
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&q);
if(ZH[p*+q]==-)
{
ZH[p*+q]=ny;
ny++;
}
g[i][ZH[p*+q]]=;
}
}
printf("%d\n",MaxMatch());
}
return ;
}
POJ 2239 Selecting Courses的更多相关文章
- poj——2239 Selecting Courses
poj——2239 Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 10656 A ...
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- 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 二分图最大匹配,基础题
1.poj 2239 Selecting Courses 二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...
- POJ 2239:Selecting Courses 选课
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 9380 Accepted: 4177 ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
- hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0
Description A new Semester is coming and students are troubling for selecting courses. Students ...
- HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)
Description A new Semester is coming and students are troubling for selecting courses. Students ...
随机推荐
- python基础-安装篇
1.安装之前我们要先去python的官网下载python的安装包 下载地址:https://www.python.org/downloads/ Python 官网有两个版本一个是3.5.2(最新版)一 ...
- SQL Server函数格式
函数格式CREATE FUNCTION -- ============================================= -- Author: Clive Chinery -- Cre ...
- ListView 分页 排序、编辑、插入和删除
摘自网络地址:http://msdn.microsoft.com/zh-cn/magazine/cc337984.aspx ListView 基础 ListView 是模板驱动的控件,这意味着它默认情 ...
- Using YARN with Cgroups testing in sparkml cluster
部署服务器: sparkml 集群 ########### sparkml ########## sparkml-node1 # yarn resource manager sparkml-node2 ...
- mac版tomcat修改端口无法访问,80端口无法访问
在mac上安装好了tomcat,修改了端口为80,没想到关闭tomcat时提示出错,而且无法访问,原来我犯了两个错误. 1.我用的是mac上的文本编辑.app打开然后修改的,重新修改为8080也不行, ...
- The Skyline Problem leetcode 详解
class Solution { public: vector<pair<int, int>> getSkyline(vector<vector<int>&g ...
- cursor:pointer 什么意思?
cursor规则是设定网页浏览时用户鼠标指针的样式,也就是鼠标的图形形状cursor:pointer设定鼠标的形状为一只伸出食指的手,这也是绝大多数浏览器里面鼠标停留在网页链接上方时候的样式另外可以选 ...
- [妙味JS基础]第七课:运算符、流程控制
知识点总结 &&(与).||(或).!(非) 与: alert(20 && 20>100) => false alert(20 && 20& ...
- linshi_temp_erweima_html_backup
<!doctype html><html><head><meta charset="utf-8"><meta content= ...
- 导入excel表格的数据--->到mysql中
01下载excel类,将Classes文件夹放入ThinkPHP\Extend\Vendor\位置 下载地址 http://phpexcel.codeplex.com/releases/view/26 ...