题意:一周上7天课,每天12节课,学校最多开设300节不同的课,每周每种课可以只有一个上课时间或者多个上课时间(上课内容一样),问一周最多可以选多少节课。

分析:二分图最大匹配,将一周84个时间点和可选的课程匹配,找出最大匹配,匈牙利。

总结:仿照poj2446的代码写的,熟悉了这种最简单的二分图匹配问题。

代码:

#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std; #define Del(x,y) memset(x,y,sizeof(x))
int map[][],vis[],link[];
int n; bool dfs(int x)
{
for(int i=;i<=n;i++)
if(map[x][i]==&&vis[i]==)
{
vis[i]=;
if(link[i]==-||dfs(link[i]))
{
link[i]=x;
return true;
}
}
return false;
} void solve()
{
int ans=;
Del(link,-);
for(int i=;i<=;i++)
{
Del(vis,);
if(dfs(i))
ans++;
}
printf("%d\n",ans);
} int main()
{
int t,p,q;
while(~scanf("%d",&n))
{
Del(map,);
for(int i=;i<=n;i++)
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&p,&q);
map[*(p-)+q][i]=;
}
}
solve();
}
return ;
}

POJ_2239_Selecting Courses的更多相关文章

  1. poj 2239 Selecting Courses (二分匹配)

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

  2. POJ 1469 COURSES

    COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20478   Accepted: 8056 Descript ...

  3. HDOJ 1083 Courses

    Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (J ...

  4. Courses

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  5. HDU-----(1083)Courses(最大匹配)

    Courses Time Limit: 20000/10000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)Total S ...

  6. POJ 1469 COURSES(二部图匹配)

                                                                     COURSES Time Limit: 1000MS   Memory ...

  7. Doing well in your courses ---- a guide by Andrej Karpathy

    Doing well in your courses a guide by Andrej Karpathy Here is some advice I would give to younger st ...

  8. Windows Kernel Security Training Courses

    http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...

  9. poj 1469 COURSES(匈牙利算法模板)

    http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS   Memory Limit: 10000K Total Submissions:  ...

随机推荐

  1. Android多媒体-MediaPlayer唤醒锁及音频焦点

    MediaPlayer的唤醒锁 一般使用MediaPlayer播放音频流,推荐使用一个Service来承载MediaPlayer,而不是直接在Activity里使用.可是Android系统的功耗设计里 ...

  2. Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButtonbutton)

    CCEditBox.CCControlSwitch.CCControlSlider.CCControlColourPicker.CCControlButton等都是Cocos2d-x 2.x的最新UI ...

  3. 中文分词实践(基于R语言)

    背景:分析用户在世界杯期间讨论最多的话题. 思路:把用户关于世界杯的帖子拉下来.然后做中文分词+词频统计,最后将统计结果简单做个标签云.效果例如以下: 兴许:中文分词是中文信息处理的基础.分词之后.事 ...

  4. 20160225.CCPP体系具体解释(0035天)

    程序片段(01):CircleList.h+CircleList.c+main.c 内容概要:环形链表 ///CircleList.h #pragma once #include <stdio. ...

  5. react 引入 百度地图API

    使用 Echarts 的地图的时候,发现报错,说 Bmap api is not loaded 百度地图API没有加载 乍一想,Echarts 用的也是 百度地图 啊,没有引入百度地图,还用个啥,当然 ...

  6. busybox的使用

    1 将busybox设置为静态链接,放在文件系统中使用 make menuconfig的时候,Busybox Settings --> Build Options --> Build Bu ...

  7. ubuntu 截图工具 Shutter,设置快捷键 Ctrl+Alt+A

    系统设置 键盘 快捷键 自定义快捷键

  8. missing required source folder

    Eclipse 中XXX is missing required source folder 问题的解决 https://blog.csdn.net/itzhangdaopin/article/det ...

  9. [Codeforces 449B] Jzzhu and Cities

    [题目链接] https://codeforces.com/contest/449/problem/B [算法] 最短路 时间复杂度 : O(N ^ 2) [代码] #include<bits/ ...

  10. window安装Elasticsearch

    下载,https://www.elastic.co/cn/downloads/elasticsearch 下载后解压,进入解压目录,运行./elasticsearch.bat 运行成功如下 (运行需要 ...