poj1274
来源:互联网 发布:优化数据库的方法 编辑:程序博客网 时间:2024/06/12 23:15
The Perfect Stall
Time Limit: 1000MS Memory Limit: 10000KTotal Submissions: 20283 Accepted: 9142
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.
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 52 2 53 2 3 42 1 53 1 2 51 2
Sample Output
4
题目大意:有n个奶牛和m个谷仓,现在每个奶牛有自己喜欢去的谷仓,并且它们只会去自己喜欢的谷仓吃东西,问最多有多少奶牛能够吃到东西分析:这里行代表奶牛,列代表谷仓将奶牛喜欢哪个谷仓就连一条边,然后求二分图的最大匹配数即可代码:var link:array [0..3000] of longint; used:array [0..3000] of boolean; f:array [0..1000,0..1000] of boolean; i,j,m,n,ans,x,a,b:longint;function check(x:longint):boolean;var i:longint;begin for i:=1 to m do begin if not used[i] and f[x,i] then begin used[i]:=true; if (link[i]=0) or check(link[i]) then begin link[i]:=x; exit(true); end; end; end; exit(false);end;begin while not eof do begin ans:=0; fillchar(f,sizeof(f),false); fillchar(link,sizeof(link),0); readln(n,m); for i:=1 to n do begin read(x); for j:=1 to x do begin read(a); f[i,a]:=true; end; readln; end; for i:=1 to n do begin fillchar(used,sizeof(used),false); if check(i) then inc(ans); end; writeln(ans); end;end.
0 0
- poj1274
- poj1274
- poj1274
- poj1274
- poj1274
- poj1274
- POJ1274
- POJ1274 The Perfect Stall
- POJ1274 The Perfect Stall
- poj1274 二分图
- poj1274 最大二分匹配
- poj1274 - The Perfect Stall
- poj1274 匈牙利算法
- poj1274 The Perfect Stall
- 二分图片匹配--poj1274
- POJ1274-二分匹配
- POJ1274 The Perfect Stall
- POJ1274(多重背包)
- 40岁应该学会的是面对和取舍
- 通过keychaini获取ios唯一标识
- Unity3D开发:为地形添加水源和效果
- 最简单的基于FFMPEG的推流器附件:收流器
- TOJ 3848 Game 矩阵快速幂
- poj1274
- 杂谈网络文学
- Nginx基本配置和性能优化
- Android 触摸事件处理机制
- CoreAnimation编程指南(四)图层树结构
- 从mysql导数据到sqlite,遇到单引号问题
- OAuth介绍
- hdu 2159 FATE
- 递归函数的理解 (三种类型)