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

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

题目大意:

在大学里有许许多多的课程,现在小明需要去选择课程,他想尽可能多的选择课程。学校里有n(1 <= n <= 300)个课程,并且学校规定,每周里的每天有12节课,那么一周就有7*12节课。要求算出小明最多可以选择多少个课程。
输入有多组数据:
每组数据第一行为n,代表有n个课程。接下来n行,每行第一个数字x代表这个课程在这一周里面共有x次课。
然后跟着x对数字,第一个p(1 <= p <= 7) 代表这周的哪一天,第二个q(1 <= q <= 12)代表这天的哪一节课.。
如果几个课程都在那d天的那c节课上课,那么你需要选择其中的一个,而不能选择多个课程
代码:
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 310
using namespace std;
bool vis[N];
int n,m,x,y,t,ans,pre[N],map[N][N];
int read()
{
    ,f=;char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=m;i++)
     if(!vis[i]&&map[x][i])
     {
         vis[i]=true;
         ||find(pre[i]))
         {
             pre[i]=x;
             ;
         }
     }
    ;
}
int main()
{
    while(~scanf("%d",&n))
    {
        ans=;m=*;
        memset(map,,sizeof(map));
        memset(pre,-,sizeof(pre));
        ;i<=n;i++)
        {
            t=read();
            while(t--)
             x=read(),y=read(),map[i][(x-)*+y]=;
        }
        ;i<=n;i++)
        {
            memset(vis,,sizeof(vis));
            if(find(i)) ans++;
        }
        printf("%d\n",ans);
    }
    ;
}

最新文章

  1. 使用命令行+ideal 工具实现本地代码项目提交
  2. (转) java定时器的几种用法
  3. python 2.43 升级到2.7
  4. iOS开发 Masonry的简单使用
  5. H5 Canvas刮刮乐
  6. HandlerMethodArgumentResolver数据绑定无效
  7. 运用加密技术保护Java源代码/定制ClassLoader
  8. vim替换及多行注释命令
  9. C++实现日期类(Date类)
  10. android studio安装后卡在fetching Android sdk compoment information
  11. 高性能网络I/O框架-netmap源码分析
  12. bzoj1042
  13. App设计相关网站
  14. git中使用命令将远程仓库拉取项目在本地文件夹
  15. webToImage (网页转图片)模块试用分享
  16. Io流的使用
  17. 用Hadoop AVRO进行大量小文件的处理(转)
  18. YYKit @autoreleasepool 使用,优化内存
  19. scrapy中Request中常用参数
  20. Stay true to yourself

热门文章

  1. [转]Qt 5.5 操作 Excel 的速度 效率问题
  2. 一行命令杀掉defunct进程
  3. Android Studio -自定义LogCat的颜色
  4. Unity复杂的旋转-欧拉角和四元数
  5. MySQL存储过程实现分页及变量的定义
  6. python程序的编辑和运行、变量
  7. Vue之computed与watch的使用
  8. JavaScript 非常重要的几个概念
  9. 点击增加删除class
  10. python基础(二) —— 流程控制语句