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,暂时只 ...
随机推荐
- Python学习笔记--XML的应用
XML的定义 XML 指可扩展标记语言(EXtensible Markup Language) XML 是一种标记语言,很类似 HTML XML 的设计宗旨是传输数据,而非显示数据 XML 标签没有被 ...
- UIImageView 的contentMode属性
UIViewContentModeScaleToFill UIViewContentModeScaleAspectFit UIViewContentModeScaleAspectFill UIView ...
- embed object以及video标签的区别以及使用
embed object以及video标签的区别以及使用?
- Android开发面试经——3.常见Java基础笔试题
Android开发(29) 版权声明:本文为寻梦-finddreams原创文章,请关注:http://blog.csdn.net/finddreams 关注finddreams博客:http:/ ...
- 20160808_卸载OpenJDK
1.查看信息 [root@localhost ~]# rpm -qa | grep jdkjava-1.6.0-openjdk-devel-1.6.0.0-1.50.1.11.5.el6_3.x86_ ...
- Office 多版本共存
1 32位共存 假如已经安装了Office 2003(必定是32位的),那么安装 32位Office 2010 时会出现如下错误: 图1.1 解决办法: 1.将下述三个注册表项导出到文件2003A.r ...
- sessionStorage
for(i=0;i<tkt.length;i++){ if(tkt[i].redEnvelopeType==1){ full1+="<div class='pic_01' id= ...
- noip2016赛后总结
面前并不是一颗变质的心. 只是一种综合并适应一切的情怀. 这或许是最好的心态... 今年的noip貌似考得好不理想呢...彻底挂了... gjs580,hgr555. 一个初三学弟570,一个400+ ...
- 反编译工具reflector破解方法
文件下载:http://files.cnblogs.com/lori/Red.Gate.Reflector7.6.rar 破解方法: 1. 断网2. 运行.NET Reflector,点击Help - ...
- [转载]Soap安全测试入门
http://www.cnblogs.com/zerotest/p/4670902.html 在SoapUI4.0引入的安全测试特点使它非常容易为你来验证你的目标服务的功能性安全,就可以评估您的系统常 ...