题目地址:http://poj.org/problem?id=1274

把每个奶牛ci向它喜欢的畜栏vi连边建图。那么求最大安排数就变成求二分图最大匹配数。

 #include<cstdio>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<stdbool.h>
#include<time.h>
#include<stdlib.h>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<vector>
using namespace std;
#define clr(x,y) memset(x,y,sizeof(x))
#define sqr(x) ((x)*(x))
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define LL long long
#define INF 0x3f3f3f3f
#define A first
#define B second
#define PI 3.14159265358979323
const int N=+;
int n,m,f[N],g[N][N],link[N]; void init()
{
clr(f,);
clr(g,);
clr(link,-);
} bool find(int x)
{
for(int i=;i<=n;i++) {
if(!f[i] && g[x][i]) {
f[i]=;
if(link[i]==- || find(link[i])) {
link[i]=x;
return true;
}
}
} return false;
} int hungary()
{
int ans=;
for(int i=;i<=n;i++) {
clr(f,);
if(find(i)) ans++;
}
return ans;
} int main()
{
int u,v,k; while(~scanf("%d%d",&n,&m)) {
init();
for(int i=;i<=n;i++) {
scanf("%d",&k);
while(k--){
scanf("%d",&v);
g[i][v]=;
}
}
printf("%d\n",hungary());
} return ;
}

[POJ] 1274 The Perfect Stall(二分图最大匹配)的更多相关文章

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

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

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

  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(二分图最大匹配)

    题意: N头牛M个牛棚,每只牛都有它自己指定的若干个它愿意呆的牛棚. 每个牛棚最多呆一头牛. 问最多可以满足多少头牛的愿望. 思路: 裸二分图最大匹配. 代码: int n,m; vector< ...

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

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

  6. [题解]poj 1274 The Perfect Stall(网络流)

    二分匹配传送门[here] 原题传送门[here] 题意大概说一下,就是有N头牛和M个牛棚,每头牛愿意住在一些牛棚,求最大能够满足多少头牛的要求. 很明显就是一道裸裸的二分图最大匹配,但是为了练练网络 ...

  7. poj —— 1274 The Perfect Stall

    The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26274   Accepted: 116 ...

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

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

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

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

随机推荐

  1. Android系统提供了哪些东西,供我们可以开发出优秀的应用程序

    1. 四大组件Android系统四大组件分别是活动(Activity).服务(Service).广播接收器(Broadcast Receiver)和内容提供器(Content Provider).其中 ...

  2. log4jdbc

    log4jdbc http://www.blogjava.net/badqiu/archive/2010/08/20/329464.html http://blog.csdn.net/sfdev/ar ...

  3. 【C++基础之十一】虚函数的用法

    虚函数的作用和意义,就不进行说明了,这里主要讨论下虚函数的用法. 1.典型的虚函数用法 可以看到,只有标识为virtual的函数才会产生多态的效果,而且是编译多态.它只能借助指针或者引用来达到多态的效 ...

  4. Go语言环境配置 Sublime Text + GoSublime+ gocode + MarGo组合

    买来<Go Web编程>一书学习Go语言,结果按照书中的步骤搭建,发现部分站点已经失效了,查了网上好多教程也没有人能够说清楚如何搭建.还是自己动手找方法吧,经过自己的不懈努力终于搭建好了. ...

  5. Cookie和Session(转)

    会话(Session)跟踪是Web程序中常用的技术,用来跟踪用户的整个会话.常用的会话跟踪技术是Cookie与Session.Cookie通过在客户端记录信息确定用户身份,Session通过在服务器端 ...

  6. poj3237 Tree

    Description You are given a tree with N nodes. The tree’s nodes are numbered 1 through N and its edg ...

  7. Html5 Canvas Hit Testing

    名词解释: Shape : 矢量图形,点线面之类的: Hit Testing : 点击测试: 参考内容: A Gentle Introduction to Making HTML5 Canvas In ...

  8. ASP.NET MVC framework 学习

    http://www.cnblogs.com/lmfeng/archive/2013/03/28/2986123.html  MVC数据绑定方式 http://www.cnblogs.com/lmfe ...

  9. HDU_2054——A=B问题

    Problem Description Give you two numbers A and B, if A is equal to B, you should print "YES&quo ...

  10. Scala-变量、常量和懒加载

    package com.mengyao.scala.function /** * Scala的变量声明和使用(可变类型和值类型) *  * @author mengyao */object Test0 ...