题目链接: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. Lintcode: Segment Tree Build

    The structure of Segment Tree is a binary tree which each node has two attributes start and end deno ...

  2. HTML基础-- 标签、表格

    <html>    --开始标签 <head> 网页上的控制信息 <title>页面标题</title> </head> <body& ...

  3. 多边形和圆的相交面积(模板)hdu2892、hdu4404

    area Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submis ...

  4. css 固定表头的表格,和 width:auto, margin:auto等 自计算方法

    实现思路: 外层用一个table,里面写好Header,然后里面再写一个table里面写好header.然后自己控制overflow的值使内部的tablemargin-top和外层的行高一致就可以实现 ...

  5. [原创]java WEB学习笔记49:文件上传基础,基于表单的文件上传,使用fileuoload 组件

    本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...

  6. C++之路进阶——codevs1285(宠物收养所)

    1285 宠物收养所  时间限制: 1 s  空间限制: 128000 KB  题目等级 : 钻石 Diamond   题目描述 Description 最近,阿Q开了一间宠物收养所.收养所提供两种服 ...

  7. ligerui_ligerTree_003_配置url参数,加载“树”

    配置url参数,加载“树”: 源码下载地址:http://download.csdn.net/detail/poiuy1991719/8571255 效果图:json.txt HTML代码: < ...

  8. 夺命雷公狗---Thinkphp----13之前台的头尾分离和导航分离

    我们在实际的开发中往往网站的头尾都是分离开来的,而且tp这点做的也很人性化,他给我们留了一个include标签可以直接引入网站的头尾部分. 我们要做的网站当然也不例外,头尾一样分离开来: 我们先用浏览 ...

  9. clock divider

    一个clock的产生: 1) Clock source的选择: cgm_mux5(.clk_out, .clk_in0, .clk_in1, .clk_in2, .clk_in3, .clk_in4, ...

  10. IUS通过PLI产生fsdb波形

    IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...