Selecting Courses
Time Limit: 1000MS   Memory Limit: 65536K
     

Description

It is well known that it is not easy to select courses in the college, for there is usually conflict among the time of the courses. Li Ming is a student who loves study every much, and at the beginning of each term, he always wants to select courses as more
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

The input contains several cases. For each case, the first line contains an integer n (1 <= n <= 300), the number of courses in Li Ming's college. The following n lines represent n different courses. In each line, the first number is an integer t (1 <= t <=
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

For each test case, output one integer, which is the maximum number of courses Li Ming can select.

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,三维邻接矩阵实现,钻数据空子。的更多相关文章

  1. poj——2239 Selecting Courses

    poj——2239   Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 10656   A ...

  2. poj 2239 Selecting Courses (二分匹配)

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8316   Accepted: 3687 ...

  3. poj 2239 Selecting Courses(二分匹配简单模板)

    http://poj.org/problem?id=2239 这里要处理的是构图问题p (1 <= p <= 7), q (1 <= q <= 12)分别表示第i门课在一周的第 ...

  4. [POJ] 2239 Selecting Courses(二分图最大匹配)

    题目地址:http://poj.org/problem?id=2239 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...

  5. POJ 2239 Selecting Courses

    二分图的最大匹配.课程和时间可以看做二分图. #include<cstdio> #include<cstring> #include<cmath> #include ...

  6. poj 2239 二分图最大匹配,基础题

    1.poj 2239   Selecting Courses   二分图最大匹配问题 2.总结:看到一个题解,直接用三维数组做的,很巧妙,很暴力.. 题意:N种课,给出时间,每种课在星期几的第几节课上 ...

  7. POJ 2239:Selecting Courses 选课

    Selecting Courses Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9380   Accepted: 4177 ...

  8. POJ 2251 Dungeon Master --- 三维BFS(用BFS求最短路)

    POJ 2251 题目大意: 给出一三维空间的地牢,要求求出由字符'S'到字符'E'的最短路径,移动方向可以是上,下,左,右,前,后,六个方向,每移动一次就耗费一分钟,要求输出最快的走出时间.不同L层 ...

  9. HDU 3697 Selecting courses(贪心)

    题目链接:pid=3697" target="_blank">http://acm.hdu.edu.cn/showproblem.php?pid=3697 Prob ...

随机推荐

  1. 51nod 1096 距离之和最小

    求中位数,注意求中位数前排序.... #include <bits/stdc++.h> using namespace std; #define LL long long const in ...

  2. ACM_数数?诶?这么简单?

    数数?诶?这么简单? Time Limit: 2000/1000ms (Java/Others) Problem Description: 当看到GDUFE-GAME宣传海报上提到"场内人员 ...

  3. Oracle10g的imp命令

    Oracle10g使用imp命令导出数据为dmp:imp system/password@orcl file=rd_online_20181102.dmp fromuser=user1 touser= ...

  4. bootmanager is missing

    问题描述: 在计算机管理->存储->磁盘管理中,因误操作,将D盘设置了"将分区标记为活动分区(M)",导致重启时无法无法进入系统,提示"bootmanager ...

  5. TestNG基本注解(一)

    TestNG基本注解   注解 描述 @BeforeSuite 注解的方法将只运行一次,运行所有测试前此套件中. @AfterSuite 注解的方法将只运行一次此套件中的所有测试都运行之后. @Bef ...

  6. LN : leetcode 123 Best Time to Buy and Sell Stock III

    lc 123 Best Time to Buy and Sell Stock III 123 Best Time to Buy and Sell Stock III Say you have an a ...

  7. pandas之groupby分组与pivot_table透视表

    zhuanzi: https://blog.csdn.net/qq_33689414/article/details/78973267 pandas之groupby分组与pivot_table透视表 ...

  8. 轻松搞定Spring+quartz的定时任务

    1.spring 的定时任务写法有两种:一种是继承工作类,一种是普通的Bean,定时写法有两种写法:一种是以时间间隔启动任务SimpleTriggerBean,一种是以时刻启动任务CronTrigge ...

  9. POI原生导入读取EXCEL

    好久没用 最近项目有冲突 所以又用到了这个 谁知道以后还会不会用 先记下来吧 直接扔项目里 调方法就OK 了. 记录一下....不想再写类似这样的东西了 import org.apache.poi.h ...

  10. zookeeper、consul 实现注册中心

    1.Zookeeper 分布式协调工具,可以实现注册中心 所有实现方式基本一致,只需要先开启zookeeper的服务端,然后再打开客户端jar包即可. Zookeeper一开始连接失败,后面又可以了, ...