题意:有n只牛,m个牛圈(大概是),告诉你每只牛想去哪个牛圈,每个牛只能去一个牛圈,每个牛圈只能装一只牛,问最多能让几只牛有牛圈住。

解法:二分图匹配。匈牙利裸题……

代码:

#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<time.h>
#include<stdlib.h>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<vector>
#define LL long long
using namespace std;
const int maxn = 205;
int n, m;
vector <int> g[maxn];
int from[maxn], tot;
bool use[maxn];
bool match(int x)
{
for(int i = 0; i < g[x].size(); i++)
if(!use[g[x][i]])
{
use[g[x][i]] = true;
if(from[g[x][i]] == -1 || match(from[g[x][i]]))
{
from[g[x][i]] = x;
return true;
}
}
return false;
}
int hungary()
{
tot = 0;
memset(from, 255, sizeof from);
for(int i = 1; i <= n; i++)
{
memset(use, 0, sizeof use);
if(match(i))
tot++;
}
return tot;
}
int main()
{
while(~scanf("%d%d", &n, &m))
{
for(int i = 1; i <= n; i++)
g[i].clear();
for(int i = 1; i <= n; i++)
{
int k;
scanf("%d", &k);
while(k--)
{
int x;
scanf("%d", &x);
g[i].push_back(x);
}
}
printf("%d\n", hungary());
}
return 0;
}

  

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——1274   The Perfect Stall Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 25709   A ...

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

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

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

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

  5. poj 1274 The Perfect Stall【匈牙利算法模板题】

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

  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: 26274   Accepted: 116 ...

  8. poj 1274 The Perfect Stall 解题报告

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

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

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

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

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

随机推荐

  1. MVC4.0中下来列表框的,两种使用方法DropDownList

    后台控制器代码 public ActionResult Drop() { var list = new List<SchoolInfo>(); list.Add(new SchoolInf ...

  2. 转一篇:文档笔记之Django QuerySet

    这个放着,说不定以后作一些更深入的查询时,用得着的. http://www.rapospectre.com/blog/7/ 今天刚刚答完辩体完检就跑来更新博客了!!! 先补上第一篇: 一般情况下,我们 ...

  3. 03 - 运行OCCI测试程序遇到0xc0150002错误

    通过控制面板->管理工具->Event Viewer->Windows Log->Application Logs, 可以看到可以看到是如下错误 “C:\Windows\ora ...

  4. Oracle的学习三:java连接Oracle、事务、内置函数、日期函数、转换函数、系统函数

    1.java程序操作Oracle java连接Oracle JDBC_ODBC桥连接 1.加载驱动: Class.forName("sun.jdbc.odbc.JdbcodbcDriver& ...

  5. 【Linux高频命令专题(5)】rmdir

    简述 rmdir是常用的命令,该命令的功能是删除空目录,一个目录被删除之前必须是空的.(注意,rm - r dir命令可代替rmdir,但是有很大危险性.)删除某目录时也必须具有对父目录的写权限. 命 ...

  6. Photoshop:模拟钢笔压力

    预期效果: 方法: 按B选择画笔工具,设置"钢笔压力" 路径描边:选择路径,右击路径,选择“描边路径” 或在路径面板,选择: 即可得到预期效果!

  7. C# Java间进行RSA加密解密交互

    原文:C# Java间进行RSA加密解密交互 这里,讲一下RSA算法加解密在C#和Java之间交互的问题,这两天纠结了很久,也看了很多其他人写的文章,颇受裨益,但没能解决我的实际问题,终于,还是被我捣 ...

  8. iOS KVO的原理

    KVO(Key Value Observing),是观察者模式在Foundation中的实现.   KVO的原理   简而言之就是:   1.当一个object有观察者时,动态创建这个object的类 ...

  9. intellij idea 注释行如何自动缩进?

    我们指代代码注释的快捷键是 Ctrl+/ 但是加注释后"//"自动放在行首,没缩进,就像这样

  10. 2、@RequestMapping注解的用法

    @RequestMapping有如下属性值: