Selecting Courses
Time Limit: 1000MS   Memory Limit: 65536K
Total Submissions: 9782   Accepted: 4400

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


#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int map[400][10][20];
int used[10][20],pipei[10][20];
int find(int x)
{
for(int i=1;i<=7;i++)
{
for(int j=1;j<=12;j++)
{
if(!used[i][j]&&map[x][i][j])
{
used[i][j]=1;
if(!pipei[i][j]||find(pipei[i][j]))
{
pipei[i][j]=x;
return 1;
}
}
}
}
return 0;
}
int main()
{
int n;
while(scanf("%d",&n)!=EOF)
{
memset(map,0,sizeof(map));
memset(pipei,0,sizeof(pipei));
for(int i=1;i<=n;i++)
{
int t;
scanf("%d",&t);
while(t--)
{
int x,y;
scanf("%d%d",&x,&y);
map[i][x][y]=1;
}
}
int sum=0;
for(int i=1;i<=n;i++)
{
memset(used,0,sizeof(used));
sum+=find(i);
}
printf("%d\n",sum);
}
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 Li Ming大学选课,每天12节课,每周7天,每种同样的课可能有多节分布在不同天的不同节.问Li Ming最多可以选多少节课. ...

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

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

  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. HDU 3697 Selecting courses(贪心)

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

  9. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  10. HDU 3697 Selecting courses(贪心+暴力)(2010 Asia Fuzhou Regional Contest)

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

随机推荐

  1. DeltaFish 校园物资共享平台 第三次小组会议

    一.想法 娄雨禛: 网页底层开发转移到后端,快速建站,效率高. 可以依照模板进行仿制. 可以考虑只进行页面设计. 但是出现问题不会调试. 所以自己写源码,做出一个大致的样子. 二.上周进度汇报 齐天杨 ...

  2. I2C controller core之Bit controller(05)

    6 generate statemachine 1 -- port cmd_ack : out std_logic; -- command completed 4 -- architecture ty ...

  3. I2C controller core之Bit controller(02)

    4 generate clock and control signals 1 -- architecture signal iscl_oen, isda_oen : std_logic; -- int ...

  4. selenium选错弹出层的下拉框

    要先选中这个弹出层的form元素,再找下拉框 public void downSelectBox(){ driver.get("https://www.imooc.com/user/setp ...

  5. Dll中的方法向外返回dynamic类型可能会失败

    如果Dll中有某个类的方法返回dynamic实例,并且dynamic对象实际实例为匿名类类型,则Dll的外部使用者可能最终无法正常使用此dynamic对象.当使用此dynamic对象时,可能会遇到x属 ...

  6. 【剑指Offer】50、数组中重复的数字

      题目描述:   在一个长度为n的数组里的所有数字都在0到n-1的范围内. 数组中某些数字是重复的,但不知道有几个数字是重复的.也不知道每个数字重复几次.请找出数组中任意一个重复的数字. 例如,如果 ...

  7. Python基础练级攻略:day01

    如果你有足够长时间做某事,一定会更擅长. 知识点: 计算机基础 变量 运算符 if语句 for-in循环 函数 列表.元组.字典.字符串.集合 ascii.unicode.utf-8.gbk 区别 A ...

  8. codevs 2602 最短路径问题——良心题解

    2602 最短路径问题 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 平面上有n个点(n<=100),每个点的坐标均在- ...

  9. UVA489 - Hangman Judge【紫书例题4.2】

    题意:就是给出一个字符串,让你去一个一个猜测,相同字母算一次,如果是之前猜过的也算错,如果你在错7次前猜对就算你赢,文章中是LRJ的例题代码. #include<stdio.h> #inc ...

  10. [luogu2679] 子串 (多维dp)

    传送门 Description 有两个仅包含小写英文字母的字符串 A 和 B . 现在要从字符串 A 中取出 k 个互不重叠的非空子串,然后把这 k 个子串按照其在字符串 A 中出现的顺序依次连接起来 ...