题目链接:http://poj.org/problem?id=1274

The Perfect Stall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 23088   Accepted: 10285

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

 
题意:
有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶牛能够吃到东西

输入第一行给出n与m
接着n行
每行第一个数代表这个奶牛喜欢的谷仓的个数P,后面接着P个数代表这个奶牛喜欢哪个谷仓

分析: 最大匹配,用匈牙利即可。

#include <stdio.h>
#include <string.h> bool maps[][];
bool use[];
int match[];
int n,m; bool DFS(int u)
{
for(int i=;i<=m;i++)
{
if(!use[i]&&maps[u][i])
{
use[i] = true;
if(match[i]==-||DFS(match[i]))
{
match[i] = u;
return true;
}
}
}
return false;
} int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(match,-,sizeof(match));
memset(maps,false,sizeof(maps));
for(int i=;i<=n;i++)
{
int num;
scanf("%d",&num);
for(int j=;j<=num;j++)
{
int v;
scanf("%d",&v);
maps[i][v] = true;
}
} int num = ;
for(int i=;i<=n;i++)
{
memset(use,false,sizeof(use));
if(DFS(i))
num++;
}
printf("%d\n",num); }
return ;
}

Poj(1274),二分图匹配的更多相关文章

  1. POJ 1274 二分图匹配

    匈牙利算法 裸题 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...

  2. POJ 3041 -- 二分图匹配

    题意:有个N*N的网格,有一部分格子里有陨石,小明有很牛逼的武器,打一枪后一行或一列的陨石就没了,给出陨石分布,求最小打炮数. 分析:其实就是Konig定理.记最小打炮数为m,在网格里你最多可以找出M ...

  3. Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖

    题意:图没什么用  给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖       最小路径覆盖=|G|-最大匹配数 ...

  4. POJ 1274 The Perfect Stall (二分图匹配)

    [题目链接] http://poj.org/problem?id=1274 [题目大意] 给出一些奶牛和他们喜欢的草棚,一个草棚只能待一只奶牛, 问最多可以满足几头奶牛 [题解] 奶牛和喜欢的草棚连线 ...

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

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

  6. POJ 1274 裸二分图匹配

    题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...

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

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

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

  9. POJ 2195 Going Home (带权二分图匹配)

    POJ 2195 Going Home (带权二分图匹配) Description On a grid map there are n little men and n houses. In each ...

  10. POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups / HDU 1699 Jamie's Contact Groups / SCU 1996 Jamie's Contact Groups (二分,二分图匹配)

    POJ 2289 Jamie's Contact Groups / UVA 1345 Jamie's Contact Groups / ZOJ 2399 Jamie's Contact Groups ...

随机推荐

  1. iOS 工程中文件变成红色是什么情况

    iOS 工程中文件变成红色是原有的文件路径改变了,系统找不到了.

  2. Swift游戏实战-跑酷熊猫 02 创建熊猫类

    要点: 如何继承SKSpriteNode :子类必须调用SKSpriteNode的一个指定构造器 init(){ super.init(texture:texture,color:UIColor.wh ...

  3. 分布式领域CAP理论

    分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...

  4. pg_stat_statements

    Functions pg_stat_statements_reset() returns void pg_stat_statements_reset discards all statistics g ...

  5. SQL 自动增长 identity

    create table Users( id ,),--id 从10000开始,增加长度为1 name ), ); --执行三次这个语句 insert into Users values('小昆虫') ...

  6. Codeforce Round #227 Div2

    这回的看错时间了! 发现理论可以涨分的- -

  7. .net 网站预编译命令

    aspnet_compiler -v /Aspnet  -p "C:\inetpub\wwwroot\a"  C:\inetpub\wwwroot\a2 /Aspnet   iis ...

  8. 转:装完Centos7提示Initial setup of CentOS Linux 7 (core)

    在用U盘装完CentOS后,重新开机启动后显示: Initial setup of CentOS Linux 7 (core) 1) [x] Creat user 2) [!] License inf ...

  9. angular 自定义指令 link

    function link(scope, element, attrs) { ... } where: scope is an Angular scope object. element is the ...

  10. 夺命雷公狗---linux之红帽的安装

    夺命雷公狗分享的第二套安装linux方法是RadHad的安装方法,,, 点击然后就自动重启了