poj1274
题解:
二分图匹配
裸题匈牙利匹配
代码:
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const int N=;
int fi[N],f[N],num,zz[N],n,m,ne[N],match[N],y,x;
int dfs(int x)
{
for (int i=fi[x];i;i=ne[i])
if (!f[zz[i]])
{
f[zz[i]]=;
if (!match[zz[i]]||dfs(match[zz[i]]))
{
match[zz[i]]=x;
return ;
}
}
return ;
}
void jb(int x,int y)
{
ne[++num]=fi[x];
fi[x]=num;
zz[num]=y;
}
int main()
{
while (~scanf("%d%d",&n,&m))
{
memset(fi,,sizeof fi);
memset(match,,sizeof match);
num=;
for (int i=;i<=n;i++)
{
scanf("%d",&y);
while (y--)
{
scanf("%d",&x);
jb(i,x);
}
}
int ans=;
for (int i=;i<=n;i++)
{
memset(f,,sizeof f);
ans+=dfs(i);
}
printf("%d\n",ans);
}
}
poj1274的更多相关文章
- poj1274 二分匹配
今天复习二分匹配,A 了一道模板题. 二分匹配需要理解增广路的寻找.用dfs来更新最大匹配.注意一些点:赋初值:愚蠢地把==写成了= ; 然后match的记值;每个点都要重新走一遍. #include ...
- poj1274 匈牙利算法 二分图最大匹配
poj1274 题意: 有n个奶牛, m个畜舍, 每个畜舍最多装1头牛,每只奶牛只有在自己喜欢的畜舍里才能产奶. 求最大产奶量. 分析: 其实题意很明显, 二分图的最大匹配, 匈牙利算法. #incl ...
- POJ-1274 The Perfect Stall---二分图模板
题目链接: https://vjudge.net/problem/POJ-1274 题目大意: 有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶 ...
- POJ1274 The Perfect Stall[二分图最大匹配]
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- poj1274(匈牙利算法)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22809 Accepted: 101 ...
- poj1274 The Perfect Stall (二分最大匹配)
Description Farmer John completed his new barn just last week, complete with all the latest milking ...
- 【poj1274】 The Perfect Stall
http://poj.org/problem?id=1274 (题目链接) 题意 懒得写了 Solution 二分图匹配裸题.注意清空数组. 代码 // poj3020 #include<alg ...
- POJ1274 The Perfect Stall【二部图最大匹配】
主题链接: id=1274">http://poj.org/problem? id=1274 题目大意: 有N头奶牛(编号1~N)和M个牛棚(编号1~M). 每头牛仅仅可产一次奶.每一 ...
- POJ1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25739 Accepted: 114 ...
- POJ1274 The Perfect Stall[二分图最大匹配 Hungary]【学习笔记】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
随机推荐
- tomcat访问管理页面出现:403 Access Denied 解决方法
点击红色框框出现以下403错误 打开context.xml文件 vim /usr/local/tomcat/webapps/manager/META-INF/context.xml <Conte ...
- 关于shared pool的深入探讨(六)-高Latch竞争案例
研究了几天shared pool,没想到忽然就撞到问题上来了.作为一个案例写出来给大家参考一下吧. 问题起因是公司做短信群发,就是那个18万买的4000字的短信小说(嘘,小声点,我也没看过...).群 ...
- 运用SQLAlchemy
result = engine.execute(s) for row in result: Info["UserId"]=row[0] Info["UserTitle&q ...
- SVN项目迁移到GIT
源项目为SVN项目, 复制一份出来后. 在VS里无法修改 源码管理器的插件为GIT. 解决方法: 删除SVN插件信息 在解决方案文件中. 删除以下SVN信息就可以了 删除后:
- linux命令(6/10):find 命令
Linux将时钟分为系统时钟(System Clock)和硬件(Real Time Clock,简称RTC)时钟两种.系统时间是指当前Linux Kernel中的时钟, 而硬件时钟则是主板上由电池供电 ...
- Zabbix Linux http 监控脚本
说明:自定义监控脚本,监控内存是否启用主进程 创建文件:vim check_http.sh #!/bin/bash result=`ps -ef | grep httpd | grep -v grep ...
- 验证环境中的program为什么必须是automatic
最近在项目中,发现验证环境中的顶层的program(一般将program作为验证环境的入口),都是automatic的. 其实Program默认是static的,那么为什么需要把验证环境做成autom ...
- MyBatis源码解读之延迟加载
1. 目的 本文主要解读MyBatis 延迟加载实现原理 2. 延迟加载如何使用 Setting 参数配置 设置参数 描述 有效值 默认值 lazyLoadingEnabled 延迟加载的全局开关.当 ...
- Hungry Rabbit
Problem C. Hungry Rabbit Input file: hungry.in Output file: hungry.out Time limit: 10 seconds Memory ...
- [mongodb] MMAPv1 Storage Engine
MMAPv1 是mongodb 在3.2以前默认的存储引擎,在3.2 之后默认的存储引擎为WiredTiger,MMAPv1存储引擎基于内存映射文件,它擅长高容量的插入,读取和更新. Journal ...