今天复习二分匹配,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 二分匹配的更多相关文章

  1. poj2239 poj1274【二分匹配】

    题意: 就是尽可能的选多的课 思路: 把课程和上课的时间看作二分图 跑一跑二分匹配就好了 #include<iostream> #include<cstdio> #includ ...

  2. POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24081   Accepted: 106 ...

  3. [kuangbin带你飞]专题十 匹配问题 二分匹配部分

    刚回到家 开了二分匹配专题 手握xyl模板 奋力写写写 终于写完了一群模板题 A hdu1045 对这个图进行 行列的重写 给每个位置赋予新的行列 使不能相互打到的位置 拥有不同的行与列 然后左行右列 ...

  4. BZOJ 1189 二分匹配 || 最大流

    1189: [HNOI2007]紧急疏散evacuate Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 1155  Solved: 420[Submi ...

  5. Kingdom of Obsession---hdu5943(二分匹配)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=5943 题意:给你两个数n, s 然后让你判断是否存在(s+1, s+2, s+3, ... , s+n ...

  6. poj 2060 Taxi Cab Scheme (二分匹配)

    Taxi Cab Scheme Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 5710   Accepted: 2393 D ...

  7. [ACM_图论] Sorting Slides(挑选幻灯片,二分匹配,中等)

    Description Professor Clumsey is going to give an important talk this afternoon. Unfortunately, he i ...

  8. [ACM_图论] The Perfect Stall 完美的牛栏(匈牙利算法、最大二分匹配)

    描述 农夫约翰上个星期刚刚建好了他的新牛棚,他使用了最新的挤奶技术.不幸的是,由于工程问题,每个牛栏都不一样.第一个星期,农夫约翰随便地让奶牛们进入牛栏,但是问题很快地显露出来:每头奶牛都只愿意在她们 ...

  9. nyoj 237 游戏高手的烦恼 二分匹配--最小点覆盖

    题目链接:http://acm.nyist.net/JudgeOnline/problem.php?pid=237 二分匹配--最小点覆盖模板题 Tips:用邻接矩阵超时,用数组模拟邻接表WA,暂时只 ...

随机推荐

  1. 货币金额的计算 - Java中的BigDecimal

    在<Effective Java>这本书中也提到这个原则,float和double只能用来做科学计算或者是工程计算,在商业计算中我们要用 java.math.BigDecimal.,而且使 ...

  2. android 属性

    RelativeLayout 第一类:属性值为true可false android:layout_centerHrizontal        水平居中 android:layout_centerVe ...

  3. Windows7睡眠后自动唤醒

    笔者的电脑(Windows7 64位旗舰版)睡眠后,隔段时间后会自动唤醒.经两项配置后,解决了该问题. 1 禁用唤醒定时器 控制面板里进入"电源选项""更改计划设置&qu ...

  4. IOC Container(服务容器)的工作机制

    IOC Container 是laravel的一个核心内容,有了IOC Container在Laravel的强大表现,我们可以在Laravel中实现很大程度的代码维护性.(文档我是看的懵逼懵逼的(*^ ...

  5. js高级程序设计(三)基本概念

    数据类型 ECMAscript中有五种简单数据类型Undefined,Null,Boolean,Number,String 还有一种复杂数据类型Object. typeof操作符 typeof可能返回 ...

  6. python 练习 2

    #!/usr/bin/python # -*- coding: utf-8 -*- from random import shuffle class caigame: win=False flag=F ...

  7. [redis] session 保存到 redis 简单实现

    参考资料: [session保存到redis简单实现]http://blog.csdn.net/ppt0501/article/details/46700221 [Redis学习]http://blo ...

  8. java synchronized静态同步方法与非静态同步方法,同步语句块

    摘自:http://topmanopensource.iteye.com/blog/1738178 进行多线程编程,同步控制是非常重要的,而同步控制就涉及到了锁. 对代码进行同步控制我们可以选择同步方 ...

  9. (20)odoo中的action

    ---------更新时间18:06 2016-09-18 星期日15:05 2016-03-14 星期一18:07 2016-02-19 星期五---------* 窗口动作   <?xml ...

  10. LDM和STM指令

    LDM批量加载/STM批量存储指令可以实现一组寄存器和一块连续的内存单元之间传输数据. 允许一条指令传送16个寄存器的任意子集和所有寄存器,指令格式如下: LDM{cond}  mode  Rn{!} ...