Poj(1274),二分图匹配
题目链接:http://poj.org/problem?id=1274
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 23088 | Accepted: 10285 |
Description
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible.
Input
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
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行
每行第一个数代表这个奶牛喜欢的谷仓的个数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),二分图匹配的更多相关文章
- POJ 1274 二分图匹配
匈牙利算法 裸题 //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> ...
- POJ 3041 -- 二分图匹配
题意:有个N*N的网格,有一部分格子里有陨石,小明有很牛逼的武器,打一枪后一行或一列的陨石就没了,给出陨石分布,求最小打炮数. 分析:其实就是Konig定理.记最小打炮数为m,在网格里你最多可以找出M ...
- Antenna Placement POJ - 3020 二分图匹配 匈牙利 拆点建图 最小路径覆盖
题意:图没什么用 给出一个地图 地图上有 点 一次可以覆盖2个连续 的点( 左右 或者 上下表示连续)问最少几条边可以使得每个点都被覆盖 最小路径覆盖 最小路径覆盖=|G|-最大匹配数 ...
- POJ 1274 The Perfect Stall (二分图匹配)
[题目链接] http://poj.org/problem?id=1274 [题目大意] 给出一些奶牛和他们喜欢的草棚,一个草棚只能待一只奶牛, 问最多可以满足几头奶牛 [题解] 奶牛和喜欢的草棚连线 ...
- POJ 1274 The Perfect Stall || POJ 1469 COURSES(zoj 1140)二分图匹配
两题二分图匹配的题: 1.一个农民有n头牛和m个畜栏,对于每个畜栏,每头牛有不同喜好,有的想去,有的不想,对于给定的喜好表,你需要求出最大可以满足多少头牛的需求. 2.给你学生数和课程数,以及学生上的 ...
- POJ 1274 裸二分图匹配
题意:每头奶牛都只愿意在她们喜欢的那些牛栏中产奶,告诉每头奶牛愿意产奶的牛棚编号,求出最多能分配到的牛栏的数量. 分析:直接二分图匹配: #include<stdio.h> #includ ...
- POJ 1274 The Perfect Stall、HDU 2063 过山车(最大流做二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 24081 Accepted: 106 ...
- 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 农夫约翰上个 ...
- POJ 2195 Going Home (带权二分图匹配)
POJ 2195 Going Home (带权二分图匹配) Description On a grid map there are n little men and n houses. In each ...
- 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 ...
随机推荐
- 分布式领域CAP理论
分布式领域CAP理论,Consistency(一致性), 数据一致更新,所有数据变动都是同步的Availability(可用性), 好的响应性能Partition tolerance(分区容错性) 可 ...
- MySQL编码问题
client 下的default_character_set=utf8; 它是需要的,可是它的作用是干吗的? 它的作用等同执行以下3个命令 SET character_set_client = utf ...
- 禁用cookie后session是如何设置的
我们都知道当在session 会话有基于cookie和基于url两种传递SESSIONID的方法.为了实现客户端禁止cookie发送的情况也不影响客户登陆网站,可以设置 php.ini中 sessio ...
- php setcookie(name, value, expires, path, domain, secure) 参数详解
setcookie() 定义一个和其余的 HTTP 标头一起发送的 cookie.和其它标头一样,cookie 必须在脚本的任何其它输出之前发送(这是协议限制).这 需要将本函数的调用放到任何输出之前 ...
- linux挂接U盘
挂接U盘fdisk -lDisk /dev/sdd: 131 MB, 131072000 bytes/dev/sdd1 * 1 889 127983+ b Win95 FAT32#mkdir -p / ...
- 去掉list重复值
/** * 去掉list重复值 */ public List<String> removeDuplicate(List<String> list) { HashSet<S ...
- IUS通过PLI产生fsdb波形
IUS通过PLI接口来调用系统函数,产生fsdb波形,再由verdi来debug. 要调用fsdbDumpfile和fsdbDumpvars,需要在testcase的shell(或.cshrc等)中设 ...
- Dreamweaver 时间轴如何打开
因为下午要辅导几个调皮捣蛋的小孩HTML, 什么能让他们感觉又简单又好玩而起又能提高他们的兴趣呢?DW中设置浮动广告吧! 想好了,动手去做.DwearmWeaver里面居然没了时间轴, 度 ...
- zw版【转发·台湾nvp系列Delphi例程】HALCON InpaintingCt2
zw版[转发·台湾nvp系列Delphi例程]HALCON InpaintingCt2 unit Unit1;interfaceuses Windows, Messages, SysUtils, Va ...
- 使用uiautomatorviewer和uiautomator来做android的UI测试
来自:http://university.utest.com 作者:Angelos Nakulas (All Authored Courses) 译者:Elaine00 目录 简介 什 ...