POJ-2239 Selecting Courses,三维邻接矩阵实现,钻数据空子。
| Time Limit: 1000MS | Memory Limit: 65536K | |
Description
as possible. Of course there should be no conflict among the courses he selects.
There are 12 classes every day, and 7 days every week. There are hundreds of courses in the college, and teaching a course needs one class each week. To give students more convenience, though teaching a course needs only one class, a course will be taught several
times in a week. For example, a course may be taught both at the 7-th class on Tuesday and 12-th class on Wednesday, you should assume that there is no difference between the two classes, and that students can select any class to go. At the different weeks,
a student can even go to different class as his wish. Because there are so many courses in the college, selecting courses is not an easy job for Li Ming. As his good friends, can you help him?
Input
7*12), the different time when students can go to study the course. Then come t pairs of integers p (1 <= p <= 7) and q (1 <= q <= 12), which mean that the course will be taught at the q-th class on the p-th day of a week.
Output
Sample Input
5
1 1 1
2 1 1 2 2
1 2 2
2 3 2 3 3
1 3 3
Sample Output
4
题意:一周7天,每天12节课,有n门课程,每一门课的时间安排如样例输入,第i行开头一个t,表示此门课可以t节课,分别在哪一天的哪一节课,求小明最多可以选多少门课;
思路:还是二分匹配问题,不过在基本二分匹配问题上稍微有点改进,好在出题人心肠不坏,数据并不是很大,于是我用三维邻接矩阵试了试,一A。
const int N=300+10;
int n,g[N][10][15],linked[20][20],v[20][20];
int dfs(int u)
{
for(int i=1;i<=7;i++)
for(int j=1;j<=12;j++)//数据范围不大,没有超时的风险。
if(!v[i][j]&&g[u][i][j])
{
v[i][j]=1;
if(linked[i][j]==-1||dfs(linked[i][j]))
{
linked[i][j]=u;
return 1;
}
}
return 0;
}
void hungary()
{
int ans=0;
memset(linked,-1,sizeof(linked));
for(int i=1;i<=n;i++)
{
memset(v,0,sizeof(v));
if(dfs(i)) ans++;
}
printf("%d\n",ans);
}
int main()
{
int i;
while(~scanf("%d",&n))
{
memset(g,0,sizeof(g));
int x;
for(i=1;i<=n;i++)
{
scanf("%d",&x);
int p,q;
while(x--)
{
scanf("%d%d",&p,&q);
g[i][p][q]=1;
}
}
hungary();
}
return 0;
}
此题很妙,运用基本二分匹配稍加修改,很考验人的想象能力与大胆实践能力。
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 Selecting Courses
二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...
- 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 ...
- POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)
POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...
- HDU 3697 Selecting courses(贪心)
题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...
随机推荐
- MyEclipse中Tomcat对应JVM的参数配置
MyEclipse中Tomcat对应JVM的参数配置: -Xmx512M -Xms256M -XX:MaxPermSize=256m
- jsp声明周期
https://www.w3cschool.cn/jsp/jsp-life-cycle.html 几点注意: jsp初始化期: 容器载入jsp文件后,它会在为请求提供任何服务前调用jspinit()方 ...
- C#控件置于底层或顶层
btn.BringToFront();//置于顶层 btn.SendToBack();//置于底层
- Android基础夯实--重温动画(四)之属性动画 ValueAnimator详解
宝剑锋从磨砺出,梅花香自苦寒来:千淘万漉虽辛苦,吹尽狂沙始到金: 长风破浪会有时,直挂云帆济沧海 一.摘要 Animator类作为属性动画的基类,它是一个抽象类,它提供了实现动画的基本架构,但是我们不 ...
- Java线程-线程的基本状态
问题:线程有哪些基本状态?这些状态是如何定义的? 新建(new):新创建了一个线程对象. 可运行(runnable):线程对象创建后,其他线程(比如main线程)调用了该对象的start()方法.该状 ...
- 使用Jenkins进行android项目的自动构建(2)
Maven and POM 1. 什么是Maven? 官方的解释是: http://maven.apache.org/guides/getting-started/index.html#What_is ...
- 洛谷 P1615 西游记公司
题目背景 一道极其无厘头的题目 题目描述 事情是这样的:西游记中的孙沙猪(孙杀猪)三徒弟在西天取经之后开始进入厦门大学经贸系学习经济,在1个小时的学习后,他们用暴力手段毕业了.然后,他们创办了三个公司 ...
- cookie设置和读取以及获取超链接参数
function setCookie(c_name, value, expiredays) { var exdate = new Date() exdate.setDate(exdate.getDat ...
- PHP自定义函数及内部函数考察点
变量的作用域和静态变量 变量的作用域 变量的作用域也称变量的范围,变量的范围即它定义的上下文背景(也是它的生效范围).大部分的PHP变量只有一个单独的范围.这个单独的范围跨度同样包含了include和 ...
- github修改仓库项目的语言类型
github是 采用Linguist来自动识别你的代码应该归为哪一类. 解决方法: 我们可以在仓库的根目录下添加.gitattributes文件: ## 使用 `.gitattributes` 配置文 ...