poj2239——Selecting Courses(二分图匹配)
来源:互联网 发布:python android 逆向 编辑:程序博客网 时间:2024/05/17 22:45
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
确定时间段为一部分,课程为另一部分。时间段的节点可以用(p-1)*12+q表示,接下来就是套模板。另外输入数据较多,scanf前要加~。
#include<cstdio>#include<cstdlib>#include<cstring>int n,time[310][310],course[310];bool use[310];bool find(int u){ for(int i=1;i<=310;++i) { if(!use[i]&&time[u][i]) { use[i]=true; if(course[i]==-1||find(course[i])) { course[i]=u; return true; } } } return false;}int sum(){ int sumall=0,i; for(i=1;i<=n;++i) { memset(use,false,sizeof(use)); if(find(i)) sumall++; } return sumall;}int main(){ int i,t,p,q; while(~scanf("%d",&n)) { memset(time,0,sizeof(time)); memset(course,-1,sizeof(course)); for(i=1; i<=n; ++i) { scanf("%d",&t); while(t--) { scanf("%d%d",&p,&q); time[i][(p-1)*12+q]=1; } } printf("%d\n",sum()); } return 0;}
- poj2239——Selecting Courses(二分图匹配)
- poj2239 Selecting Courses --- 二分图最大匹配
- POJ2239 Selecting Courses【二分图最大匹配】
- POJ2239 Selecting Courses(二分图)
- poj2239 Selecting Courses(最大二分图匹配 (匈牙利算法) 实现 )
- POJ2239 Selecting Courses(二分图匹配,匈牙利算法)
- 二分匹配 Selecting Courses
- poj Selecting Courses(二分图最大匹配)
- POj 2239 Selecting Courses(二分图匹配)
- POJ 2239 Selecting Courses(二分图匹配)
- poj Selecting Courses 2239 (二分图最大匹配)
- hdu 2239 Selecting Courses(二分图最大匹配)
- 2239 Selecting Courses 二分图匹配
- POJ 2239 - Selecting Courses(二分图匹配)
- Selecting Courses(二分图匹配 Hungary算法)
- poj2239 - Selecting Courses
- poj2239 Selecting Courses
- POJ2239:Selecting Courses
- 通过Excel批量生成对应的SQL语句
- Resource temporarily unavailable,errno代码为11(EAGAIN)
- 文件上传、下载测试用例
- [Android]修改Android Studio项目的运行版本
- 逻辑回归 机器学习基础(2)
- poj2239——Selecting Courses(二分图匹配)
- Linux 中的零拷贝技术 一
- iOS UIApplication微解
- Volley源码解析
- 程序猿之华丽转身:必备技术面试手册
- 观察者模式
- Python语言实践分析 -- 包导入
- laravel之发送邮件
- 蓝桥杯 带分数(搜索)