嗯...

题目链接:http://poj.org/problem?id=1274

一道很经典的匈牙利算法的题目:

将每只奶牛看成二分图中左边的点,将牛圈看成二分图中右边的点,如果奶牛看上某个牛圈,就将两点之间连边,然后跑一边匈牙利就行了...

AC代码:

 #include<cstdio>
#include<iostream>
#include<cstring> using namespace std; int n, m, match[], g[][], vis[]; inline int dfs(int u){
for(int i = ; i <= m; i++){
if(g[u][i] && !vis[i]){
vis[i] = ;
if(!match[i] || dfs(match[i])){
match[i] = u;
return ;
}
}
}
return ;
} inline int hungary(){
int ans = ;
for(int i = ; i <= n; i++){
memset(vis, , sizeof(vis));
if(dfs(i)) ans++;
}
return ans;
} int main(){
while(~scanf("%d%d", &n, &m)){
memset(g, , sizeof(g));
memset(match, , sizeof(match));
for(int i = ; i <= n; i++){
int s;
scanf("%d", &s);
for(int j = ; j <= s; j++){
int t;
scanf("%d", &t);
g[i][t] = ;
}
}
printf("%d\n", hungary());
}
return ;
}

AC代码

POJ 1274 The Perfect Stall(二分图 && 匈牙利 && 最小点覆盖)的更多相关文章

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

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

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

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

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

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

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

  5. poj——1274 The Perfect Stall

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

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

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

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

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

  9. POJ 1274 The Perfect Stall (二分图匹配)

    [题目链接] http://poj.org/problem?id=1274 [题目大意] 给出一些奶牛和他们喜欢的草棚,一个草棚只能待一只奶牛, 问最多可以满足几头奶牛 [题解] 奶牛和喜欢的草棚连线 ...

随机推荐

  1. 【转载】 __declspec(dllexport) 和__declspec(dllimport)

    转自:http://www.cppblog.com/Dutyboy/archive/2010/11/15/133699.html __declspec(dllexport)   __declspec( ...

  2. LitElement(一)概述

    1.一些感悟 自从踏入编程领域开始,从html,css,JavaScript,jQuery,bootstrap开始接触前端,经常用NodeJS,ejs等模板语言来写个简单的页面,感觉蛮简单的,也不怎么 ...

  3. APP开发工具如何选?

    随着技术的发展,在当前开发一款APP已经非常的简单和快速.特别是近些年,利用HTML5技术将APP的开发门槛进一步降低.各种开发工具和框架层出不穷,令人眼花缭乱.这么多的工具摆在眼前应该如何进行选择呢 ...

  4. DVWA的安装及报错解决

    PS:我是在wamp5集成环境中搭建的 1.解压下载好的DVWA安装包到www目录下 DVWA安装包: https://pan.baidu.com/s/1ivnwiH53gIV5jWU5IyeD0Q ...

  5. 随笔js

    js中的函数定义之后,函数名就是这个函数(JS中函数其实也是对象)的地址(句柄) js读取函数内存地址: 首先想读内存地址只有C或者C++,汇编抛开不谈,其他高级语言一般都封装起来了,不过我也不能确定 ...

  6. 每天进步一点点------ORCAD Capture CIS

    ORCAD Capture CIS 一.建工程及设置 1.选主菜单 file->new->project ;弹出 project wizard 对话框,取名Myproject : Mypr ...

  7. python入门(二十讲):爬虫

    什么是爬虫? 按照一定的规则,自动地抓取万维网信息的程序或脚本. 爬虫目的: 从网上爬取出来大量你想获取类型的数据,然后用来分析大量数据的类似点或者其他信息来对你所进行的工作提供帮助. 为什么选择py ...

  8. AcWing 851. spfa求最短路 边权可能为负数。 链表 队列

    #include <cstring> #include <iostream> #include <algorithm> #include <queue> ...

  9. 概率dp lightoj 1342

    题意:有N根木棍,每根木棍都有一个权值 其中有若干根可识别,若干根不可识别的,抽到了可识别的棍子,就不放回,抽到了不可识别的,就要放回 ,问所有棍子都至少被抽过一次后权值和的期望 不可识别的棍子,就相 ...

  10. robotframework初始化时有返回值怎么处理

    方法一:set suite variable/set global variable 假设执行add school class会返回一个id,这个id在后面的脚本中还要使用. 因为初始化时只能有一个关 ...