poj 2239 Selecting Courses(二分匹配简单模板)
http://poj.org/problem?id=2239
这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第p天的第q节课上
其中二分图的X集合里表示课程i,那么我们要解决的就是Y集合了
将第i门课在一周的第p天的第q节课上进行编号,这样Y集合就是
上课时间的编号了
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<queue>
#include<algorithm>
#define INF 0x3f3f3f3f
#define N 310 using namespace std; int G[N][N], maps[N][N], vis[N], used[N];
int n, x; bool Find(int u)
{
int i;
for(i = ; i <= x ; i++)
{
if(!vis[i] && G[u][i])
{
vis[i] = ;
if(!used[i] || Find(used[i]))
{
used[i] = u;
return true;
}
}
}
return false;
} int main()
{
int p, q, n, i, j, m;
x = ;
memset(maps, , sizeof(maps));
for(i = ; i <= ; i++)
{
for(j = ; j <= ; j++)
{
maps[i][j] = x++;
}
}//构图
while(~scanf("%d", &n))
{
memset(G, , sizeof(G)); for(i = ; i <= n ; i++)
{
scanf("%d", &m);
while(m--)
{
scanf("%d%d", &p, &q);
G[i][maps[p][q]] = ;
}
}
memset(used, , sizeof(used));
int ans = ;
for(i = ; i <= n ; i++)
{
memset(vis, , sizeof(vis));
if(Find(i))
ans++;
}
printf("%d\n", ans);
}
return ;
}
poj 2239 Selecting Courses(二分匹配简单模板)的更多相关文章
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- 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 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...
- POJ 2239 Selecting Courses
二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...
- POJ 1469(裸二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 18993 Accepted: 7486 Descript ...
- POJ-1274The Perfect Stall,二分匹配裸模板题
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23313 Accepted: 103 ...
- poj 3057(bfs+二分匹配)
题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区 ...
- poj 1469 COURSES (二分匹配)
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 16877 Accepted: 6627 Descript ...
- poj 2594 Treasure Exploration (二分匹配)
Treasure Exploration Time Limit: 6000MS Memory Limit: 65536K Total Submissions: 6558 Accepted: 2 ...
随机推荐
- content management system
Defination of CMS: The definition of a CMS is an application (more likely web-based), that provides ...
- HDU 1505 City Game
这题是上一题的升级版 关键在于条形图的构造,逐行处理输入的矩阵,遇到'F'则在上一次的条形图基础上再加1,遇到'R'则置为0 然后用上一题的算法,求每行对应条形图的最大矩阵的面积. 另外:本来是deb ...
- Hadoop实战课程
Hadoop生态系统配置Hadoop运行环境Hadoop系统架构HDFS分布式文件系统MapReduce分布式计算(MapReduce项目实战)使用脚本语言Pig(Pig项目实战)数据仓库工具Hive ...
- [转载]mysql的binlog安全删除
[转载]mysql的binlog安全删除 理论上,应该在配置文件/etc/my.cnf中加上binlog过期时间的配置项,expire_logs_days = 10 但是如果没有加这一项,随着产生越 ...
- [反汇编练习] 160个CrackMe之024
[反汇编练习] 160个CrackMe之024. 本系列文章的目的是从一个没有任何经验的新手的角度(其实就是我自己),一步步尝试将160个CrackMe全部破解,如果可以,通过任何方式写出一个类似于注 ...
- Python内置数据类型之Dictionary篇
1.查看函数XXX的doc string. Python的函数是有属性的,doc string便是函数的属性.所以查看函数XXX的属性的方法是模块名.XXX.__doc__ 2.模块的属性 每个模块都 ...
- swun 1612 合并果子
//思路:这题思路似乎很简单,每次取出最小的两个堆合并, //但是由于数据太大,不能采取每次进行排序的方式,所以 //想到用优先队列,以数据小的优先级更高为标准,但是 //优先队列中的数据默认情况 ...
- Spring的5种通知
1.前置通知 Before advice Advice that executes before a join point, but which does not have the ability ...
- 【转】Eclipse编辑shell的插件(shellEd)
原文网址:http://blog.sina.com.cn/s/blog_a42d507e01019mlp.html Eclipse官方网站:http://download.eclipse.org/ 1 ...
- jad安装
见:http://www.myexception.cn/eclipse/1469829.html 最开始看了一个坑爹的博客,由于是低级菜鸟一直被误导(设置的是.class的打开方式) 执行完链接够的步 ...