poj 1274 The Perfect Stall

2019独角兽企业重金招聘Python工程师标准>>> hot3.png


The Perfect Stall

Time Limit: 1000MS Memory Limit: 10000K
Total Submissions: 16888 Accepted: 7721

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 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2

Sample Output

4

Source

USACO 40


我的解答:

二分图匹配.匈牙利算法.


/*=============================================================================
#     FileName: 1274.cpp
#         Desc: poj 1274
#       Author: zhuting
#        Email: cnjs.zhuting@gmail.com
#     HomePage: my.oschina.net/locusxt
#      Version: 0.0.1
#    CreatTime: 2013-12-07 15:54:43
#   LastChange: 2013-12-07 15:54:43
#      History:
=============================================================================*/
#include <cstdio>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#define maxn 205bool mymap[maxn][maxn] = {0};/*记录是否两点相连*/
int link[maxn] = {0};/*记录右边的点所连接的点,没有时置-1*/
bool cover[maxn] = {0};/*记录右边的某个点有没有被覆盖,防止死循环*/
int n = 0, m = 0;bool find (int x)/*寻找左边的点*/
{for (int i = 0; i < m; ++i)/*对右边的点进行遍历*/{if (!cover[i] && mymap[x][i])/*如果该右点没有被覆盖,并且与左点x之间有线相连*/{cover[i] = 1;if (link[i] == -1 || find(link[i])){link[i] = x;return 1;}}}return 0;
}void init()
{memset(mymap, 0, sizeof(mymap));memset(cover, 0, sizeof(cover));memset(link, 0xff, sizeof(link));return;
}int main()
{int link_num = 0;int stall = 0;while (scanf("%d%d", &n, &m) != EOF){int ans = 0;init();for (int i = 0; i < n; ++i){scanf("%d", &link_num);for (int j = 0; j < link_num; ++j){scanf("%d", &stall);mymap[i][stall - 1] = 1;}}for (int i = 0; i < n; ++i)/*遍历所有左点*/{memset(cover, 0, sizeof(cover));if (find(i))++ans;}printf("%d\n", ans);}return 0;
}


第一道二分图,匈牙利算法




转载于:https://my.oschina.net/locusxt/blog/182353

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/461797.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

C++远征之封装篇——常对象成员、常成员函数

一、常对象成员 二、常成员函数 &#xff08;1&#xff09;常成员函数中不能修改数据成员的值 &#xff08;2&#xff09;不能修改的原因 每个函数都默认带了一个this指针的&#xff0c;该指针指向该类的实例。当使用const来修饰时&#xff0c;其实是const Coordinate* this。这…

PHP建站环境搭建:汇总网上常见的1键安装包

PHP的程序很火&#xff0c;像博客&#xff1a;Wordpress、论坛&#xff1a;Discuz!、SNS&#xff1a;UCenter Home、CMS&#xff1a;DedeCMS等等都是比较流行的PHP程序&#xff0c;大家都在使用PHP类的程序&#xff0c;但对于很多初学者来说&#xff0c;直接上传到虚拟空间上一…

最长公共子序列|最长公共子串|最长重复子串|最长不重复子串|最长回文子串|最长递增子序列|最大子数组和...

最长公共子序列|最长公共子串|最长重复子串|最长不重复子串|最长回文子串|最长递增子序列|最大子数组和文章作者&#xff1a;Yx.Ac 文章来源&#xff1a;勇幸|Thinking (http://www.ahathinking.com) 转载请注明&#xff0c;谢谢合作。 以后新博客写的文章挑一些粘过来&#…

JEECMS编辑漏洞及随便拿webshell,啊哈哈

JEECMS是基于java技术开发&#xff0c;继承其强大、稳定、安全、高效、跨平台等多方面的优点 采用SpringMVC3Spring3Hibernate3Freemarker主流技术架构 安全性做得非常变态&#xff0c;当网站安装完成后就不再允许执行任何目录下的jsp文件了&#xff08;web.xml配置了过滤器禁…

内核通识——linux内核的简介

以下内容源于朱有鹏嵌入式课程的学习与整理&#xff0c;如有侵权请告知删除。 内核下载 下载地址&#xff1a;www.kernel.org 下载地址&#xff1a;Index of /sites/ftp.kernel.org/pub/linux/kernel/ 本栏目文章2.6.35.7版本为例进行说明。 一、内核功能 1、操作系统的含义 操…

端口列表详解

tyle"margin:20px 0px 0px; font-size:14px; line-height:26px; font-family:Arial; color:rgb(51,51,51); text-align:left"> TCP 2Death TCP 11Skun TCP 12Bomber TCP 16Skun TCP 17Skun TCP 18消息传输协议,skun TCP 19Skun TCP 20FTP Data,Amanda TCP 21文件传…

C++之内存管理

1.申请内存&#xff1a;int *p new int;释放内存&#xff1a;delete p; 2.申请块内存&#xff1a;int *arrnew int[10];释放:delete []arr; 3.申请内存需要判断是否成功&#xff0c;释放内存需要设空指针 4.new与delete配套使用 转载于:https://www.cnblogs.com/xjyxp/p/11236…

Android 调用分享框

平时打开某些应用的分享选项时&#xff0c;经常可以看到同时分享到google play, 豌豆荚&#xff0c;91助手等弹出框&#xff0c;具体怎样实现的呢&#xff1f; 可以参考下面的代码 Uri uri Uri.parse("market://details?id"Constant.PACKAGE_NAME);Intent intent …

内核通识——linux内核源码(2.6.35.7版本)的目录结构

以下内容源于朱有鹏嵌入式课程的学习与整理&#xff0c;如有侵权请告知删除。 一、文件 &#xff08;1&#xff09;Kbuild文件 Kbuild是kernel build的缩写&#xff0c;就是内核编译的意思。这个文件就是linux内核特有的内核编译体系需要用到的文件。 &#xff08;2&#xff09…

【原创】自制PCB经验教训之一:版图打印篇

看了篇帖子《用感光电路板自制PCB攻略&#xff08;网友电子白菜撰写&#xff09;》&#xff0c;于是前几天在淘宝上买了一批PCB DIY工具和材料回来&#xff0c;想自己弄个试试&#xff0c;岂料障碍重重&#xff0c;甚至于酿成大祸... 首先是PCB打印的软件设置问题&#xff0c;我…

magento cms page、登錄頁面修改(增加)breadcrumbs

由於magento的cms功能有限&#xff0c;在cms page的角度來看&#xff0c;差不存在cms的category&#xff0c;所以cms page的breadcrumbs只會出現單層的結構&#xff08;HOME->About Us), 要想模仿出分層次的結構&#xff0c;就需要修改cbreadcrumbs了。 修改方法如下&#x…

分享一套非常不错的bootstarp3.0.2响应式模板

2019独角兽企业重金招聘Python工程师标准>>> 这是销量第一的bootstrap 响应式后台管理模板&#xff0c;每套模板都是我用20美金买回来的话不多说&#xff0c;下面是五个模板的演示地址&#xff0c;你看到的&#xff0c;就是你可以下载到的。都是收费模板。 官方演示…

内核配置与编译——编译初体验

以下内容源于朱有鹏嵌入式课程的学习与整理&#xff0c;如有侵权请告知删除。 一、获取内核源码 第一种是kernel.org的官方版本&#xff0c;第二种是三星移植过的&#xff0c;第三种是X210的移植版本。讲课时使用第三种内核&#xff0c;移植实验使用第二种内核。九鼎配置好的k…

10 个理由让你继续干 IT

1.钱&#xff0c;钱&#xff0c;钱对&#xff0c;我们努力工作就是为了赚钱&#xff0c;而IT专业人士的努力工作的确得到了很好的补偿。报酬不仅仅是好而已&#xff0c;而是非常棒。根据美国劳工部《2010年美国 就业与报酬情况概览》&#xff08;表6&#xff0c;PDF&#xff09…

脱机下载至校验成功的脚本

今天又差点在 root 权限下破坏了系统 (归功于破坏力极强的 build-sysroot.sh), 心想逐步把写过的一些小工具备份。 sureget #!/bin/sh if [ -z $2 ]; thenfnamebasename "$1" elsefname$2 fiwhile true; do[ -f $fname ] && rm -f $fnamewget -c $1 -O $fnam…

MySQL同步状态双Yes的假象及seconds_behind_master的含义

近期由于特殊原因有一台主库宕机了一个小时没有处理&#xff0c;说起来这是个挺不好啥意思的事情&#xff0c;但是由于这个事情反而发现个比较诡异的情况&#xff0c;那就是在主库宕机一个小时候后&#xff0c;监控才发出从库IO thread中断的报警&#xff0c;也就是说在那一个小…

内核配置与编译——内核的配置原理

以下内容源于朱有鹏嵌入式课程的学习与整理&#xff0c;如有侵权请告知删除。 概述 编译内核前需要进行两步配置&#xff0c;即先make x210ii_qt_defconfig&#xff0c;然后再make menuconfig。第一步如果成功&#xff0c;则会提示“configuration written to .config”。注意…

gluPickMatrix和glReadPixels

gluPickMatrix的使用2008年12月03日 星期三 23:40void gluPickMatrix(GLdouble x,GLdouble y,GLdouble width,GLdouble height,GLint viewport[4]); 它是用来根据当前鼠标选择区域生成一个相应的投影矩阵的。这里面头两个参数不是这个选择区域的左上角位置&#xff0c;而是整个…

STM32的串口通信

在基础实验成功的基础上&#xff0c;对串口的调试方法进行实践。硬件代码顺利完成之后&#xff0c;对日后调试需要用到的printf重定义进行调试&#xff0c;固定在自己的库函数中。 b) 初始化函数定义&#xff1a; void USART_Configuration(void); //定义串口初始化函…

感谢大家对我微软TECHED2013课程的支持

http://technet.microsoft.com/zh-cn/teched2013_hols 转载于:https://blog.51cto.com/136840/1339733