POJ_2239_Selecting Courses
题意:一周上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的更多相关文章
- poj 2239 Selecting Courses (二分匹配)
Selecting Courses Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 8316 Accepted: 3687 ...
- POJ 1469 COURSES
COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 20478 Accepted: 8056 Descript ...
- HDOJ 1083 Courses
Hopcroft-Karp算法模板 Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (J ...
- Courses
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- HDU-----(1083)Courses(最大匹配)
Courses Time Limit: 20000/10000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total S ...
- POJ 1469 COURSES(二部图匹配)
COURSES Time Limit: 1000MS Memory ...
- 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 ...
- Windows Kernel Security Training Courses
http://www.codemachine.com/courses.html#kerdbg Windows Kernel Internals for Security Researchers Thi ...
- poj 1469 COURSES(匈牙利算法模板)
http://poj.org/problem?id=1469 COURSES Time Limit: 1000MS Memory Limit: 10000K Total Submissions: ...
随机推荐
- mingw32-gcc.exe: error: CreateProcess: No such file or directory
用code::blocks在windows平台下,搭建object c编译环境时,出现这个错误. 解决的方法: 将setting -> compliler -> Toolchain exe ...
- web面试集合
在JavaScript中,添加到页面上的事件处理程序数量将直接关系到页面的整体运行性能.导致这一问题的原因是多方面的.首先,每个函数都是对象,都会占用内存:内存中的对象越多,性能就越差.其次,必须事先 ...
- ibatis 取消查询动态列的缓存
ibatis在查询结果列不确定(或是动态变化)的情况下,会因为列缓存的原因导致变化后的列数据查不出来 解决方法是: select标签有个属性remapResults,该属性默认值为false,设置成r ...
- shell如何查看单个或多个文件的行数或总行数
shell如何查看单个或多个文件的行数或总行数_百度经验 https://jingyan.baidu.com/article/cbf0e500b8470f2eab28937d.html 单个文件 ...
- SpringMVC_RESTRUL_CRUD
编写POJO Departmet: package org.springmvc.curd.entity; public class Department { private int id; priva ...
- 利用游标返回结果集的的例子(Oracle 存储过程)JAVA调用方法和.NET调用方法
在sqlplus中建立如下的内容: 1.程序包 SQL> create or replace package types 2 as 3 type cursorType is re ...
- Mac系统打开命令行终端及查看操作系统版本号的方法
Mac系统打开命令行终端的方法: 应用程序 --> 实用工具 --> 终端 Mac系统终端查看操作系统版本号的方法: 输入:#more /System/Library/CoreServic ...
- MySQL 基础 —— 数据类型、各种变量
1. 基本数据类型 char:prod_id char(10),括号内的内容表示字符的长度 decimal:十进制,不带参数为整数(四舍五入) text:文本类型,长度不限 2. 日期和时间处理函数 ...
- mysql将查询结果导出csv文件的方法into outfile
例句: select * from table_name into outfile '/tmp/tmp.csv' fields terminated by ','; 详解: ① into outf ...
- mybatis 注解写法 多层嵌套foreach,调用存储过程,批量插入数据
@Select("<script>" + "DECLARE @edi_Invoice_Details edi_Invoice_Details;" + ...