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

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

模板题:

 //168K    16MS    C++    960B    2014-06-03 12:15:26
#include<iostream>
#include<vector>
#define N 205
using namespace std;
vector<int>V[N];
int vis[N];
int match[N];
int n,m;
int dfs(int u)
{
for(int i=;i<V[u].size();i++){
int v=V[u][i];
if(!vis[v]){
vis[v]=;
if(match[v]==- || dfs(match[v])){
match[v]=u;
return ;
}
}
}
return ;
}
int hungary()
{
memset(match,-,sizeof(match));
int ret=;
for(int i=;i<=n;i++){
memset(vis,,sizeof(vis));
ret+=dfs(i);
}
return ret;
}
int main(void)
{
int k,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
for(int i=;i<=n;i++) V[i].clear();
for(int i=;i<=n;i++){
scanf("%d",&k);
while(k--){
scanf("%d",&a);
V[i].push_back(a);
}
}
printf("%d\n",hungary());
}
return ;
}

poj 1274 The Perfect Stall (二分匹配)的更多相关文章

  1. poj 1274 The Prefect Stall - 二分匹配

    Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22736   Accepted: 10144 Description Far ...

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

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

  3. 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 农夫约翰上个 ...

  4. poj——1274 The Perfect Stall

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

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

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

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

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

  7. POJ-1274The Perfect Stall,二分匹配裸模板题

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 23313   Accepted: 103 ...

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

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

  9. poj —— 1274 The Perfect Stall

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

随机推荐

  1. 【转】odoo装饰器:model

    model装饰器的作用是返回一个集合列表,一般用来定义自动化动作里面,该方法无ids传入. 应用举例: 定义columns langs = fields.Selection(string=" ...

  2. 每天看一片代码系列(一):stream.js

    简介 stream.js是一个小型的js库,用于处理stream相关的操作.这里的stream是指一种数据结构,它像数组一样,可以放置多个类型的数据,但是并不限制长度,甚至可以达到无限长.可以对该数据 ...

  3. 【BZOJ1176】[BOI2007]Mokia 摩基亚

    [BZOJ1176][BOI2007]Mokia 摩基亚 题面 bzoj 洛谷 题解 显然的\(CDQ\)\(/\)树套树题 然而根本不想写树套树,那就用\(CDQ\)吧... 考虑到点\((x1,y ...

  4. dubbo之基础应用

    一.Dubbo是Alibaba开源的分布式服务框架,它最大的特点是按照分层的方式来架构,使用这种方式可以使各个层之间解耦合(或者最大限度地松耦合).从服务模型的角度来看,Dubbo采用的是一种非常简单 ...

  5. 阅读笔记《JavaScript语言精粹》

    阅读笔记<JavaScript语言精粹> 对象 1.检索属性 使用[]和. 2.引用传递 JavaScript的简单数据类型包括数字.字符串.布尔值.null值和undefined值.其它 ...

  6. Servlet处理文件下载的编码问题,乱码。

    Servlet处理文件下载的编码问题,乱码. //处理文件名乱码问题 // 获得请求头中的User-Agent String agent = request.getHeader("User- ...

  7. 关于mongodb的mapReduce

    由于nodejs本身的限制,在程序中使用js进行大批量计算效率不高.而V8引擎自身对内存大小的限制(64位系统下1.4G),同样限制了数据规模. 因此,相对于从mongodb中抽出数据进行计算,在mo ...

  8. 「暑期训练」「基础DP」免费馅饼(HDU-1176)

    题意与分析 中文题就不讲题意了.我是真的菜,菜出声. 不妨思考一下,限制了我们决策的有哪些因素?一,所在的位置:二,所在的时间.还有吗?没有了,所以设dp[i][j]" role=" ...

  9. WEB中间件漏洞--IIS

    1.iis安装 版本 一直下一步,选上iis安装 端口修改 网站目录 通过网站发布目录(发布目录任意),新建index.html页面,可以正常访问 2.iis6.0解析漏洞 (1)文件名解析 IIS在 ...

  10. 使用gitlab时候 fork仓库不会实时从主仓库更新解决方案

    付费用户可以使用现成的方案,地址见 链接 但是私有gitlab时候,需要手动进行如下操作 1. Clone your fork: git clone git@github.com:YOUR-USERN ...