poj1274 二分匹配
今天复习二分匹配,A 了一道模板题。
二分匹配需要理解增广路的寻找。用dfs来更新最大匹配。注意一些点:赋初值;愚蠢地把==写成了= ; 然后match的记值;每个点都要重新走一遍。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#define INF 80005
#define maxn 405
using namespace std;
int n,m,ans,match[maxn];
int tot,he[maxn],to[INF],ne[INF];
bool check[maxn];
void add(int a,int b)
{
tot++;to[tot]=b;ne[tot]=he[a];he[a]=tot;
}
bool findway(int x)
{
for (int i=he[x];i;i=ne[i])//dfs
if (!check[to[i]]){
check[to[i]]=true;
if (match[to[i]]==-||findway(match[to[i]])){ //not findway(to[i])
match[to[i]]=x;//<qwq> == not =
return true;
}
}
return false;
}
int KM ()//hungray
{
ans=;
memset(match,-,sizeof (match));
for (int i=;i<=n;i++) //if (match[i]=-1)
{
memset(check,,sizeof (check));
if (findway(i)) ans++;
}
return ans;
}
int main()
{
freopen("poj1274.in","r",stdin);
while (cin>>n>>m){
memset(ne,,sizeof(ne));
memset(to,,sizeof (to));
memset(he,,sizeof (he));
tot=;//赋初值
for (int i=;i<=n;i++)
{
int a;scanf("%d",&a);
for (int j=;j<=a;j++)
{
int b;scanf("%d",&b);
b+=n;//!!!
add(i,b);add(b,i);
}
}
printf("%d\n",KM());
}
return ;
}
poj1274 二分匹配的更多相关文章
- poj2239 poj1274【二分匹配】
题意: 就是尽可能的选多的课 思路: 把课程和上课的时间看作二分图 跑一跑二分匹配就好了 #include<iostream> #include<cstdio> #includ ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- [kuangbin带你飞]专题十 匹配问题 二分匹配部分
刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...
- BZOJ 1189 二分匹配 || 最大流
1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec Memory Limit: 162 MBSubmit: 1155 Solved: 420[Submi ...
- Kingdom of Obsession---hdu5943(二分匹配)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...
- poj 2060 Taxi Cab Scheme (二分匹配)
Taxi Cab Scheme Time Limit: 1000MS Memory Limit: 30000K Total Submissions: 5710 Accepted: 2393 D ...
- [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)
Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...
- [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)
描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...
- nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖
题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...
随机推荐
- STM32学习笔记(二) 基于STM32-GPIO的流水灯实现
学会了如何新建一个工程模板,下面就要开始动手实践了.像c/c++中经典的入门代码"hello world"一样,流水灯作为最简单的硬件设备在单片机领域也是入门首推.如果你已经有了一 ...
- 转:Teach Yourself Programming in Ten Years——用十年教会自己编程
转自:http://blog.csdn.net/UndeadWraith/article/details/6140455 作者:Peter Norvig 译者:刘海粟 本文原文为:http://nor ...
- Freemarker 浅析 (zhuan)
http://blog.csdn.net/marksinoberg/article/details/52006311 ***************************************** ...
- hiho_1049 二叉树遍历
题目大意 给出一棵二叉树的前序和中序遍历结果,求出后序遍历的结果.保证二叉树中节点值均不相同. 分析 通过前序和中序遍历的结果,我们可以构建出二叉树,若构建出二叉树,则后序遍历的结果很容易求出(当然递 ...
- nosql简述
1.NoSQL数据库概念 NoSQL数据库是非关系型数据库,主要是针对关系型数据库而言,它主要是用来解决半结构化数据和非机构化数据的存储问题. 2.为什么使用NoSQL数据库? (1)对数据库的高并发 ...
- maven各种插件在总结
http://blog.csdn.net/taiyangdao/article/category/6377863 好文章系列课程
- ResponseUtil反射制造唯一结果
调用:通过反射调用同一个类型的返回值 return fillResponse(response,Constants.SUCCESS,"获取数据成功","taskList& ...
- eclipse+adt+sdk开发环境搭配
1.开发环境配置 http://www.mamicode.com/info-detail-516839.html
- hook_schema 小总结
1, primary key 可以带空格 做为下表 但field就不行 2, dev_node 仅为下标 'primary key' => array('nid'), 'foreign k ...
- semantic-ui dropdown is not a function
按照semantic-ui官网示例,编写了如下示例,却不见效果. <div class="ui secondary menu"> <a class="i ...