The Perfect Stall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 21665   Accepted: 9735

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

  1. 5 5
  2. 2 2 5
  3. 3 2 3 4
  4. 2 1 5
  5. 3 1 2 5
  6. 1 2

Sample Output

  1. 4

Source


  1. #include<stdio.h>
  2. #include<string.h>
  3. #include<vector>
  4. #include<algorithm>
  5. using namespace std;
  6. vector<int>map[220];
  7. int pipei[220],used[220];
  8. int find(int x)
  9. {
  10. for(int i=0;i<map[x].size();i++)
  11. {
  12. int y=map[x][i];
  13. if(!used[y])
  14. {
  15. used[y]=1;
  16. if(!pipei[y]||find(pipei[y]))
  17. {
  18. pipei[y]=x;
  19. return 1;
  20. }
  21. }
  22. }
  23. return 0;
  24. }
  25. int main()
  26. {
  27. int n,m;
  28. while(scanf("%d%d",&n,&m)!=EOF)
  29. {
  30. int num,y;
  31. memset(pipei,0,sizeof(pipei));
  32. for(int i=1;i<=n;i++)
  33. {
  34. map[i].clear();
  35. scanf("%d",&num);
  36. while(num--)
  37. {
  38. scanf("%d",&y);
  39. map[i].push_back(y);
  40. }
  41. }
  42. int sum=0;
  43. for(int i=1;i<=n;i++)
  44. {
  45. memset(used,0,sizeof(used));
  46. sum+=find(i);
  47. }
  48. printf("%d\n",sum);
  49. }
  50. return 0;
  51. }

poj--1274--The Perfect Stall(最大匹配)的更多相关文章

  1. Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配)

    Luogu 1894 [USACO4.2]完美的牛栏The Perfect Stall / POJ 1274 The Perfect Stall(二分图最大匹配) Description 农夫约翰上个 ...

  2. poj——1274 The Perfect Stall

    poj——1274   The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25709   A ...

  3. POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配

    两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...

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

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

  5. poj 1274 The Perfect Stall 解题报告

    题目链接:http://poj.org/problem?id=1274 题目意思:有 n 头牛,m个stall,每头牛有它钟爱的一些stall,也就是几头牛有可能会钟爱同一个stall,问牛与 sta ...

  6. poj —— 1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26274   Accepted: 116 ...

  7. poj 1274 The Perfect Stall【匈牙利算法模板题】

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 20874   Accepted: 942 ...

  8. poj 1274 The Perfect Stall (二分匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 17768   Accepted: 810 ...

  9. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

  10. POJ 1274 The Perfect Stall(二分图最大匹配)

    题意: N头牛M个牛棚,每只牛都有它自己指定的若干个它愿意呆的牛棚. 每个牛棚最多呆一头牛. 问最多可以满足多少头牛的愿望. 思路: 裸二分图最大匹配. 代码: int n,m; vector< ...

随机推荐

  1. 苹果双系统win8.1遇到的一些问题

    MacBook air是一款不错的电脑,详细没研究就不叙述好与坏了.只此记录自己使用这款笔记本遇到的问题. 一.安装双系统win8.1 1.下载镜像文件—>拷贝到ios内存中,一个8GU盘.ht ...

  2. js基础标签用法

    js是脚本语言,开始标签<script type="text/javascript">.......结束标签</script>.script通常放在< ...

  3. 修改withdraw 方法

    修改withdraw 方法 练习目标-使用有返回值的方法:在本练习里,将修改withdraw方法以返回一个布尔值来指示交易是否成功. 任务 1. 修改Account类 修改deposit 方法返回tr ...

  4. Linux rsync配置用于服务器之间传输大量的数据

    Linux的rsync 配置,用于服务器之间远程传大量的数据   [教程主题]:rsync [课程录制]: 创E [主要内容] [1] rsync介绍 Rsync(Remote Synchronize ...

  5. change project compliance and jre to 1.5

    这个主要检查一下几点 项目的jdk为1.7 java版本设置为1.7 java compiler 的页面设置为以下,并且去掉勾选java compiler 下面的 enableproject spec ...

  6. Ad hoc polymorphism

    与面向对象中的接口类或抽象类中定义的函数组类似: 函数的具体执行依赖与函数医用的类型. In programming languages, ad-hoc polymorphism[1] is a ki ...

  7. MVC 返回404,返回图片,流到数组,apk信息

    return HttpNotFound(); byte[] buffer0 = QRCode(); return File(buffer0, @"image/jpeg"); // ...

  8. 验证:java 主线程在子线程结束后才会结束

    package com.idealisan.test; /** * Hello world! * */ public class App { public static void main( Stri ...

  9. Windows数字代码签名的作用和流程

    什么是数字代码签名?数字签名代码是一种技术,它使用数字证书来识别软件的发布商和使用hash算法来确保软件的完整性.数字签名使用公共密匙签名书法被创建,它使用两种不同的密匙:公共密匙和私有密匙,我们称其 ...

  10. Labview学习笔记(一)

    一.概述 Labview是一种工业标准图形化编程工具,主要用于开发测试.测量与控制系统,拥有一个可以完成任何编程任务的庞大函数库,包括数据采集.GPIB.串口控制.数据分析.数据显示及数据存储等. L ...