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;
}

最新文章

  1. [LeetCode] Moving Average from Data Stream 从数据流中移动平均值
  2. C#进阶系列——AOP?AOP!
  3. 4809 江哥的dp题c
  4. MyBatis java and MySql local variables
  5. HW4.8
  6. POJ 2653 Pick-up sticks(线段相交)
  7. ASP.NET MVC3 系列教程 – 新的Layout布局系统
  8. Android学习之Notification
  9. C#实现给手机发送短信
  10. Java基于Socket文件传输示例
  11. 0 - Dao层(数据访问层设计)
  12. [LeetCode] 9. 回文数
  13. Zookeeper+Kafka集群部署
  14. vue 导出excel表格
  15. Downloading jQuery 3.2.1
  16. Spring开发 - 通过实现ApplicationContextAware在Servlet中调用注解的Service
  17. Python3.x:import urllib2报错解决方案
  18. LDAP Error Codes
  19. Python实例---利用正则实现计算器[FTL版]
  20. 团队Alpha冲刺(九)

热门文章

  1. TypeError: Object function (req, res, next) { app.handle(req, res, next); } has no method &#39;configure&#39;
  2. 【Oracle】详解10053事件
  3. 【python】os.getcwd和getcwdu
  4. 转:Fiddler抓包工具总结
  5. 时序分析:ARIMA模型(非平稳时间序列)
  6. Canopy聚类算法分析
  7. Windows Live Writer 历史Blog修改的功能
  8. ssl_protocols和ssl_ciphers应该怎么配置
  9. gitlab变更邮箱后发送邮件报SSLError错误
  10. PHP并发IO编程实践