poj1274 The Perfect Stall (二分最大匹配)
发布日期:2021-08-19 16:00:59 浏览次数:1 分类:技术文章

本文共 2591 字,大约阅读时间需要 8 分钟。

Description

Farmer John completed his new barn just last week, complete with all the latest milking technology. Unfortunately, due to engineering problems, all the stalls in the new barn are different. For the first week, Farmer John randomly assigned cows to stalls, but it quickly became clear that any given cow was only willing to produce milk in certain stalls. For the last week, Farmer John has been collecting data on which cows are willing to produce milk in which stalls. A stall may be only assigned to one cow, and, of course, a cow may be only assigned to one stall. 
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible. 

Input

The input includes several cases. For each case, the first line contains two integers, N (0 <= N <= 200) and M (0 <= M <= 200). N is the number of cows that Farmer John has and M is the number of stalls in the new barn. Each of the following N lines corresponds to a single cow. The first integer (Si) on the line is the number of stalls that the cow is willing to produce milk in (0 <= Si <= M). The subsequent Si integers on that line are the stalls in which that cow is willing to produce milk. The stall numbers will be integers in the range (1..M), and no stall will be listed twice for a given cow.

Output

For each case, output a single line with a single integer, the maximum number of milk-producing stall assignments that can be made.

Sample Input

5 52 2 53 2 3 42 1 53 1 2 51 2

Sample Output

4 二分最大匹配模板题;

 AC代码:

#include 
#include
#include
#include
using namespace std;int n,m,g[203][203],visit[203],match[203],num,a;int dfs(int x){ for(int i=1;i<=m;i++) { if(!visit[i]&&g[x][i]) { visit[i]=1; if(match[i]==-1||dfs(match[i])) { match[i]=x; return 1; } } } return 0;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { memset(g,0,sizeof(g)); memset(match,-1,sizeof(match)); for(int i=1;i<=n;i++) { scanf("%d",&num); while(num--) { scanf("%d",&a); g[i][a]=1; } } int ans=0; for(int i=1;i<=n;i++) { memset(visit,0,sizeof(visit)); if(dfs(i))ans++; } printf("%d\n",ans); } return 0;}

 

 

 

转载于:https://www.cnblogs.com/zhangchengc919/p/5154988.html

转载地址:https://blog.csdn.net/weixin_30940783/article/details/97956641 如侵犯您的版权,请留言回复原文章的地址,我们会给您删除此文章,给您带来不便请您谅解!

上一篇:hdu-5695 Gym Class(贪心+拓扑排序)
下一篇:阿里云服务器部署

发表评论

最新留言

留言是一种美德,欢迎回访!
[***.207.175.100]2024年03月07日 06时02分56秒

关于作者

    喝酒易醉,品茶养心,人生如梦,品茶悟道,何以解忧?唯有杜康!
-- 愿君每日到此一游!

推荐文章

单系统 台电x80pro_台电x80 pro (ID:E3E6)安装remix OS系统教程整理 2019-04-21
linux存储pdf伟岸_python的reportlab库介绍、制作pdf和作图 2019-04-21
安徽信息技术初中会考上机考试模拟_2020年中小学寒假、考试时间定下了! 2019-04-21
ubuntu 退出anaconda环境_从零开始深度学习第15讲:ubuntu16.04 下深度学习开发环境搭建与配置... 2019-04-21
稳定币usda是哪个发行的_武夷山币装帧款曝光,共4款设计,你喜欢哪款? 2019-04-21
可变车道怎么走不违章_走ETC竟比人工车道贵50%!交警:这3点不知道,吃亏的是自己... 2019-04-21
苹果笔记本的end键_笔记本用户的大烦恼:触控板,想好好用你不容易 2019-04-21
趣玩机器人什么时候成立的_【直播回顾】当我们谈机器人集成调试的时候在谈什么... 2019-04-21
中考大数据大连79_中考大数据 | 大连部分初中2019年中考指标生录取最低分及人数统计!... 2019-04-21
vue 地理位置定位_HTML5地理位置 2019-04-21
pac代理模式什么意思_托管仓库租赁电商仓储运营模式托管什么意思 2019-04-21
validated 验证数组_在 Laravel 中处理请求验证的智能方法 2019-04-21
洞泾智能机器人产业基地_G60科创走廊洞泾人工智能产业基地(核心区块)暨洞泾镇招商人员培训班顺利开班... 2021-06-24
java 拼接路径优雅方式_Java安全编码实践总结 2021-06-24
realme x2 深度测试打不开_搭载65W超级闪充,realme真我X7手机充电评测 2021-06-24
整数取反编程_【每日编程185期】数字的补数 2021-06-24
能用别的软件吗_手机软件能用蓝牙传送吗 2021-06-24
为什么图片要2的倍数_为什么宝宝喜欢流“口水”?这种2种原因父母要知道,建议收藏... 2021-06-24
下载了XAMPP怎样打开MYSQL_xampp mysql安装启动 2021-06-24
pdo转mysql_mysql转mysqli或pdo 2021-06-24