The Perfect Stall
Hal Burch

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.

PROGRAM NAME: stall4

INPUT FORMAT

Line 1: One line with 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.
Line 2..N+1: N lines, each corresponding 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.

SAMPLE INPUT (file stall4.in)

5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2

OUTPUT FORMAT

A single line with a single integer, the maximum number of milk-producing stall assignments that can be made.

SAMPLE OUTPUT (file stall4.out)

4

——————————————————————————————————
二分图匹配匈牙利算法模板
算法简述:
对于当前点x,选一个点y进行匹配,如果这个点y与另一点x'匹配,进行递归知道为x'找到另一个分配或无法找到另一分配
 /*
ID:ivorysi
PROG:stall4
LANG:C++
*/
#include <iostream>
#include <cstdio>
#include <cstring>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#define inf 0x7fffffff
#define ivorysi
#define siji(i,x,y) for(int i=(x);i<=(y);++i)
#define gongzi(j,x,y) for(int j=(x);j>=(y);--j)
#define xiaosiji(i,x,y) for(int i=(x);i<(y);++i)
#define sigongzi(j,x,y) for(int j=(x);j>(y);--j)
#define p(x) (x)*(x)
using namespace std;
vector<int> g[];
int used[],from[];
int n,m,ans;
bool find(int x){
used[x]=;
for(int i=;i<g[x].size();++i) {
if(from[g[x][i]]) {
if(used[from[g[x][i]]]== && find(from[g[x][i]])) {
from[g[x][i]]=x;
return true;
}
}
else {
from[g[x][i]]=x;
return true;
}
}
return false;
}
void init() {
scanf("%d%d",&n,&m);
int s,b;
siji(i,,n) {
scanf("%d",&s);
siji(j,,s) {
scanf("%d",&b);
g[i].push_back(b+);
}
} }
void solve() {
init();
siji(i,,n) {
memset(used,,sizeof(used));
if(find(i)) ++ans;
}
printf("%d\n",ans);
}
int main(int argc, char const *argv[])
{
#ifdef ivorysi
freopen("stall4.in","r",stdin);
freopen("stall4.out","w",stdout);
#else
freopen("f1.in","r",stdin);
#endif
solve();
return ;
}
 

最新文章

  1. ajax实现下拉菜单无刷新加载更多
  2. mongoDB在windows下安装与配置方案
  3. C#利用SMTP服务器发送邮件
  4. 使用CSS3实现百叶窗
  5. php header setcookie headers_sent函数 函数检查 HTTP 标头是否已被发送以及在哪里被发送
  6. 静态页面中如何传json数据
  7. [转] STL源码学习----lower_bound和upper_bound算法
  8. mysql查询字段值为数字
  9. GCC精彩之旅_2(转)
  10. 【MM系列】SAP库龄报表逻辑理解
  11. HOW TO ANSWER: Tell Me About Yourself
  12. 上传程序Dictionary 字典 哈希--多读一写锁ReaderWriterLock
  13. 基于python2【重要】怎么自行搭建简单的web服务器
  14. Git之版本回退及回滚
  15. 【用jQuery来判断浏览器的类型】及【javascript获取用户ip地址】
  16. 第12课:HTML+CSS的基础用法
  17. SEO -- WP如何建立SiteMap
  18. 【C#】编码史记
  19. 独立看门狗实验-IWDG
  20. 讯飞SDK的使用

热门文章

  1. ubuntu下使用openocd+jlink进行STM32开发调试
  2. 在weblogic11g发布该项目时遇到错误(不支持web-app_3_0)
  3. CLR中的垃圾回收机制
  4. How To Configure Logging And Log Rotation In Apache On An Ubuntu VPS
  5. YARN
  6. Nginx+phpfastcgi下flush输出问题
  7. [原]使用MachOView辅助破解AppStore应用
  8. 批量转换cue文件编码
  9. js闭包(转)
  10. Cracking the Coding Interview(Trees and Graphs)