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

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

题目描述:农夫约翰刚刚在上周完成了他的新谷仓,配备了所有最新的挤奶技术。 不幸的是,由于工程问题,新谷仓中的所有摊位都不一样。 第一周,农夫约翰随机分配奶牛到摊位,但很快就明白,任何给定的牛只愿意在某些摊位生产牛奶。 最近一周,农民约翰一直收集有关哪些奶牛愿意生产牛奶的数据。 摊位可能只能分配给一只母牛,当然,一只母牛可能只能被分配到一个摊位。考虑到奶牛的偏好,计算可能的奶牛产奶量的最大数量。
 
二分图的最大匹配
代码;
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#define N 505
using namespace std;
bool vis[N];
int n,m,k,x,ans,girl[N],map[N][N];
int read()
{
    ,f=; char ch=getchar();
    ; ch=getchar();}
    +ch-'; ch=getchar();}
    return x*f;
}
int find(int x)
{
    ;i<=m;i++)
    {
        if(!vis[i]&&map[x][i])
        {
            vis[i]=true;
            ||find(girl[i])){girl[i]=x; ;}
        }
    }
    ;
}
int main()
{
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        ans=;
        memset(map,,sizeof(map));
        memset(girl,-,sizeof(girl));
        ;i<=n;i++)
        {
            k=read();
            ;
        }
        ;i<=n;i++)
        {
            memset(vis,,sizeof(vis));
            if(find(i)) ans++;
        }
        printf("%d\n",ans);
    }
    ;
}

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【匈牙利算法模板题】

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

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

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

  7. poj 1274 The Perfect Stall 解题报告

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

  8. [题解]poj 1274 The Perfect Stall(网络流)

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

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

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

随机推荐

  1. AJPFX关于StringBuffer类的总结

    StringBuffer类一.字符串缓冲区,是一个容器.没有子类不能继承.特点:长度可变化:可操作多个数据类型:可通过toString()变成字符串.二.存储方法1.StringBuffer appe ...

  2. (六)Mybatis总结之延迟加载

    应用场景: i.假如一个用户他有N个订单(N>=1000),那么如果一次性加载的话,一个用户对象的订单集合OrderList里面就会有1000多个Order的对象.计算:一个订单对象里面数据有多 ...

  3. 自学 iOS - 三十天三十个 Swift 项目 第二天

    继续做仿造着别人的第二个 1.首先下载 一些字体 网上搜索 "造字工房" 2.把下载的相应字体文件放到工程之中,就Ok了 不多说 效果如下 可以下面这个方法 检索项目里面所有的字体 ...

  4. Scala基础篇-函数式编程的重要特性

    1.纯函数 表示函数无副作用(状态变化). 2.引用透明性 表示对相同输入,总是得到相同输出. 3.函数是一等公民 函数与变量.对象.类是同一等级.表示可以把函数当做参数传入另一个函数,或者作为函数的 ...

  5. Websocket 关闭浏览器报错

    这个报错,是因为你关闭之后,websocket 自动连接失败造成的 只要在你的websocket 运行的类里面加上: @OnError public void onError(Throwable e, ...

  6. swift potocol 作为参量时函数的派发顺序

    1.检查protocol本体是否声明调用函数: 2.如果没有,检查protocol扩展是否有该函数:如果扩展中也没有,报错: 3.如果本体声明了函数,使用动态派发机制进行派发:扩展中的实现位于最末位.

  7. Kotlin:数组、字符串模板

    一.数组 Kotlin 中的数组是带有类型参数的类,其元素类型被指定为相应的类型参数,使用 Array 类来表示, Array 类定义了 get 与 set 函数(按照运算符重载约定这会转变为 [ ] ...

  8. wifi钓鱼之--Pumpkin

    无线钓鱼   前言:请准备一块rt3070的外接网卡 Pumpkin是一款无线安全检测工具WiFi-Pumpkin的使用,利用该工具可以伪造接入点完成中间人攻击,同时也支持一些其它的无线渗透功能.旨在 ...

  9. ansible中yaml语法应用

    4.yaml语法应用 ansible的playbook编写是yaml语言编写,掌握yaml语法是编写playbook的必要条件,格式要求和Python相似,具体教程参考如下 yaml语言教程 附上一个 ...

  10. hdfs深入:07、hdfs的文件的读取过程

    详细步骤解析 1. Client向NameNode发起RPC请求,来确定请求文件block所在的位置: 2. NameNode会视情况返回文件的部分或者全部block列表,对于每个block,Name ...