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

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

Source

POJ Monthly,Li Haoyuan
 
给出课程和课程可以上的时间,求一周最多可以上几门课。
    开始以为是最大独立集,然后构图时想不出完整的解决方法,后来感觉不对,应该没那么难,看了下别人的思路后才发现其实是最大匹配。
构图还是不够灵活啊..
    以课程和可上的课时间作匹配,一周最多有12*7节课,所以最多也是有这么多门课可以选到。此为切入点。
 
 //224K    32MS    C++    1154B    2014-06-08 09:36:09
//构图思想很重要..
#include<iostream>
#include<vector>
#define N 105
using namespace std;
int p[N];
vector<int>V[*N];
int match[N];
int vis[N];
int n;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
int ret=;
memset(match,-,sizeof(match));
for(int i=;i<n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int m,a,b;
while(scanf("%d",&n)!=EOF)
{
memset(p,,sizeof(p));
for(int i=;i<=n;i++) V[i].clear();
memset(p,,sizeof(p));
int pos=;
for(int i=;i<n;i++){
scanf("%d",&m);
for(int j=;j<m;j++){
scanf("%d%d",&a,&b);
if(!p[(a-)*+b])
p[(a-)*+b]=++pos;
V[i].push_back(p[(a-)*+b]);
}
}
printf("%d\n",hungary());
}
return ;
}

poj 2239 Selecting Courses (二分匹配)的更多相关文章

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

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

  2. poj——2239 Selecting Courses

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

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

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

  4. POJ 2239 Selecting Courses

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

  5. POJ 1469(裸二分匹配)

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 18993   Accepted: 7486 Descript ...

  6. poj 3057(bfs+二分匹配)

    题目链接:http://poj.org/problem?id=3057 题目大概意思是有一块区域组成的房间,房间的边缘有门和墙壁,'X'代表墙壁,'D'代表门,房间内部的' . '代表空区域,每个空区 ...

  7. poj 1469 COURSES (二分匹配)

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 16877   Accepted: 6627 Descript ...

  8. poj 2594 Treasure Exploration (二分匹配)

    Treasure Exploration Time Limit: 6000MS   Memory Limit: 65536K Total Submissions: 6558   Accepted: 2 ...

  9. poj 2584 T-Shirt Gumbo (二分匹配)

    T-Shirt Gumbo Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 2571   Accepted: 1202 Des ...

随机推荐

  1. ECharts使用心得总结(二)

    Echarts使用心得总结(二) 前言: 前一段时间一直都挺忙的,各种事,也没来得及每周的总结,趁着晚上的一点时间把项目中用的Echart中常用的各种图表给抽象总结了一下,趁着周末跟大家分享一下.之前 ...

  2. Kafka安装及部署

    安装及部署 一.环境配置 操作系统:Cent OS 7 Kafka版本:0.9.0.0 Kafka官网下载:请点击 JDK版本:1.7.0_51 SSH Secure Shell版本:XShell 5 ...

  3. linux 下 ntfs移动硬盘挂载

    fdisk -l Disk /dev/sdb: 500.0 GB, 500074283008 bytes255 heads, 63 sectors/track, 60797 cylindersUnit ...

  4. java程序打包成jar文件,使用到第三方jar包

    1.右击工程选择Export—>选择JAR file—>选择NEXT,如下图所示 2.选择需要打包的工程,并且选择存放目录,我这放在 E:\jartest 目录下,然后点击NEXT,如下图 ...

  5. java byte转无符号int

    import java.io.ByteArrayInputStream; public class Test{ public static void main(String[] args) { byt ...

  6. c++ 中__declspec 的用法

    __declspec ( extended-decl-modifier-seq )扩展修饰符:1:align(#)    用__declspec(align(#))精确控制用户自定数据的对齐方式 ,# ...

  7. [FFmpeg] ffmpeg参数详解

    ffmpeg 参数语法 ffmpeg [[options][`-i' input_file]]... {[options] output_file}... 如果没有输入文件,那么视音频捕捉就会起作用. ...

  8. .net 中生成二维码的组件

    http://qrcodenet.codeplex.com/

  9. Farey Sequence

    Description The Farey Sequence Fn for any integer n with n >= 2 is the set of irreducible rationa ...

  10. 八、MPxToolCommand, tool command

    1. Tool Property Sheets: 是用来更改context属性的编辑框,类似于attribute editor.(property和attribute本质上是一个意思)作用于activ ...