The Perfect Stall
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 20874   Accepted: 9421

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

题意:奶牛只在指定的摊位才肯产奶,第一行输入n,m分别代表母牛数量和摊位的数量,接下来m行,第i行就代表第i头奶牛,每行开头一个数k代表接下来这一行要输入的摊位号

匈牙利算法模板都快忘了  复习一下 以后也不能老刷模板题
#include<stdio.h>
#include<string.h>
#include<algorithm>
#define MAX 210
using namespace std;
int n,m;
int cow[MAX][MAX],space[MAX];
int vis[MAX];
int find(int x)
{
int i,j;
for(i=1;i<=m;i++)
{
if(cow[x][i]&&!vis[i])
{
vis[i]=1;
if(space[i]==0||find(space[i]))
{
space[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int i,j,t,a;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(cow,0,sizeof(cow));
memset(space,0,sizeof(space));
for(i=1;i<=n;i++)
{
scanf("%d",&t);
for(j=1;j<=t;j++)
{
scanf("%d",&a);
cow[i][a]=1;
}
}
int sum=0;
for(i=1;i<=n;i++)
{
memset(vis,0,sizeof(vis));
if(find(i))
sum++;
}
printf("%d\n",sum);
}
return 0;
}

  

poj 1274 The Perfect Stall【匈牙利算法模板题】的更多相关文章

  1. POJ 1325 && 1274:Machine Schedule 匈牙利算法模板题

    Machine Schedule Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 12976   Accepted: 5529 ...

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

  3. poj——1274 The Perfect Stall

    poj——1274   The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25709   A ...

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

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

  5. poj 1274 The Perfect Stall 解题报告

    题目链接:http://poj.org/problem?id=1274 题目意思:有 n 头牛,m个stall,每头牛有它钟爱的一些stall,也就是几头牛有可能会钟爱同一个stall,问牛与 sta ...

  6. POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)

    嗯... 题目链接:http://poj.org/problem?id=1274 一道很经典的匈牙利算法的题目: 将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将 ...

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

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

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

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

  9. POJ 3041 匈牙利算法模板题

    一开始预习是百度的算法 然后学习了一下 然后找到了学长的ppt 又学习了一下.. 发现..居然不一样... 找了模板题试了试..百度的不好用 反正就是wa了..果然还是应当跟着学长混.. 图两边的点分 ...

随机推荐

  1. python开发-web框架之diango-----Models

    这篇博客是紧连上一篇博客的,因为内容较多,这里介绍的是Models这一部分的内容 七:Models 数据库的配置 1    django默认支持sqlite,mysql, oracle,postgre ...

  2. lucene解决全文检索word2003,word2007的办法

    在上一篇文章中 ,lucene只能全文检索word2003,无法检索2007,并且只能加载部分内容,无法加载全文内容.为解决此问题,找到了如下方法 POI 读取word (word 2003 和 wo ...

  3. JavaNIO之Channel

    Channel的本质是通道,用来连接JVM之外数据向JVM内传输数据,比如来自于硬盘的文件,来自于网络的数据包.JVM之外的数据就是通过Channel进行数据传输:如果把Channel比作河道,那么作 ...

  4. 定位 - MapKit - 基本使用

    /** *  Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Co ...

  5. Aspose.Cells 导入导出EXCEL(转)

    Aspose.Cells 导入导出EXCEL      修改样式        Workbook workbook = new Workbook(); //工作簿          Worksheet ...

  6. 启动python解释器的命令(python manage.py shell和python的区别)

    如果你曾经使用过Python,你一定好奇,为什么我们运行python manage.py shell而不是python.这两个命令都会启动交互解释器,但是manage.py shell命令有一个重要的 ...

  7. ACMer程序员智力拾遗

           浏览网页偶得,遂记录下来,每天进步一点点--        博客园真是个不错的平台,今天我让师姐也注册了--        学会分享吧,孩子们-- 一.编程中无穷大量的设置        ...

  8. 【Spring】Spring IOC原理及源码解析之scope=request、session

    一.容器 1. 容器 抛出一个议点:BeanFactory是IOC容器,而ApplicationContex则是Spring容器. 什么是容器?Collection和Container这两个单词都有存 ...

  9. Android Training精要(一)ActionBar上级菜单导航图标

    Navigation Up(ActionBar中的上级菜单导航图标) 在android 4.0中,我们需要自己维护activity之间的父子关系. 导航图标ID为android.R.id.home @ ...

  10. PLSQL调用webservice

      1.   用途简介 为什么要在Oracle中访问WebService?在系统实现中,有时会有直接在数据库端利用触发器.存储过程等方式进行数据传递.分发的业务,而其中可能会涉及一些业务逻辑,为了处理 ...