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
二分最大匹配模板题;

AC代码:

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,g[][],visit[],match[],num,a;
int dfs(int x)
{
for(int i=;i<=m;i++)
{
if(!visit[i]&&g[x][i])
{
visit[i]=;
if(match[i]==-||dfs(match[i]))
{
match[i]=x;
return ;
}
}
}
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(g,,sizeof(g));
memset(match,-,sizeof(match));
for(int i=;i<=n;i++)
{
scanf("%d",&num);
while(num--)
{
scanf("%d",&a);
g[i][a]=;
}
}
int ans=;
for(int i=;i<=n;i++)
{
memset(visit,,sizeof(visit));
if(dfs(i))ans++;
}
printf("%d\n",ans);
}
return ;
}
 

poj1274 The Perfect Stall (二分最大匹配)的更多相关文章

  1. POJ1274 The Perfect Stall[二分图最大匹配]

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

  2. POJ1274 The Perfect Stall[二分图最大匹配 Hungary]【学习笔记】

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

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

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

  4. POJ1274_The Perfect Stall(二部图最大匹配)

    解决报告 http://blog.csdn.net/juncoder/article/details/38136193 id=1274">题目传送门 题意: n头m个机器,求最大匹配. ...

  5. POJ1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25739   Accepted: 114 ...

  6. poj 1274 The Perfect Stall (二分匹配)

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

  7. poj--1274--The Perfect Stall(最大匹配)

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21665   Accepted: 973 ...

  8. POJ1274 The Perfect Stall【二部图最大匹配】

    主题链接: id=1274">http://poj.org/problem? id=1274 题目大意: 有N头奶牛(编号1~N)和M个牛棚(编号1~M). 每头牛仅仅可产一次奶.每一 ...

  9. [POJ] 1274 The Perfect Stall(二分图最大匹配)

    题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...

随机推荐

  1. Servlet-中文乱码

    背景 从Tomcat5.x开始,GET,POST方法提交信息,Tomcat采用不同的方式来处理编码. 对于GET请求,Tomcat不会考虑使用request.setCharacterEncoding( ...

  2. xshell下载文件到本地/上传文件到服务器

    xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...

  3. c#反射获取常量属性名以及其值(真正可用)

    最近因为要开发rpc平台的c#客户端,其中部分常量类为了自动加载的map,需要反射解析出静态常量,往上搜了一堆,都各种的不靠谱. 亲自研究了下,如下: Type t = typeof(SpiderEr ...

  4. CSS应用内容补充及小实例

    一.clear 清除浮动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  5. Android笔记——Android中数据的存储方式(二)

    我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...

  6. 如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)

    本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩 ...

  7. cocospods的安装与应用

    安装cocospods 一,升级Ruby环境 ~ xxx$ sudo gem update --system   二,安装Cocoapods时需要访问cocoapods.org,该网站可能被墙掉,但是 ...

  8. C++ RTTI

    一.定义:RTTI:Run Time Type Identification ,运行时类型识别:指程序能够使用基类的指针或引用来检索其所指对象的实际派生类型.二.使用方式:C++中有两个操作符提供RT ...

  9. CocoaPod出现-bash: pod: command not found 解决办法

    从过年来到公司  就不用自己电脑了    之前一直自己带电脑   昨天随便建了一个demo   使用cocoapods  发现     -bash: pod: command not found 刚开 ...

  10. 编译iOS程序时的-all_load选项,以及-all_load 导致的 ld duplicate symbol xx的问题

    在新的SDK环境中调试百度地图的应用程序时,app总是意外退出,找了半天发现错误的原因是unrecognized selector xx的错误,另外还有报了一个Unknown class XXX in ...