poj1274 The Perfect Stall (二分最大匹配)
Description
Given the preferences of the cows, compute the maximum number of milk-producing assignments of cows to stalls that is possible.
Input
Output
Sample Input
5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2
Sample Output
4
二分最大匹配模板题;
AC代码:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
int n,m,g[][],visit[],match[],num,a;
int dfs(int x)
{
for(int i=;i<=m;i++)
{
if(!visit[i]&&g[x][i])
{
visit[i]=;
if(match[i]==-||dfs(match[i]))
{
match[i]=x;
return ;
}
}
}
return ;
}
int main()
{
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(g,,sizeof(g));
memset(match,-,sizeof(match));
for(int i=;i<=n;i++)
{
scanf("%d",&num);
while(num--)
{
scanf("%d",&a);
g[i][a]=;
}
}
int ans=;
for(int i=;i<=n;i++)
{
memset(visit,,sizeof(visit));
if(dfs(i))ans++;
}
printf("%d\n",ans);
}
return ;
}
poj1274 The Perfect Stall (二分最大匹配)的更多相关文章
- POJ1274 The Perfect Stall[二分图最大匹配]
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- POJ1274 The Perfect Stall[二分图最大匹配 Hungary]【学习笔记】
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23911 Accepted: 106 ...
- POJ-1274The Perfect Stall,二分匹配裸模板题
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 23313 Accepted: 103 ...
- POJ1274_The Perfect Stall(二部图最大匹配)
解决报告 http://blog.csdn.net/juncoder/article/details/38136193 id=1274">题目传送门 题意: n头m个机器,求最大匹配. ...
- POJ1274 The Perfect Stall
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25739 Accepted: 114 ...
- poj 1274 The Perfect Stall (二分匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 17768 Accepted: 810 ...
- poj--1274--The Perfect Stall(最大匹配)
The Perfect Stall Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21665 Accepted: 973 ...
- POJ1274 The Perfect Stall【二部图最大匹配】
主题链接: id=1274">http://poj.org/problem? id=1274 题目大意: 有N头奶牛(编号1~N)和M个牛棚(编号1~M). 每头牛仅仅可产一次奶.每一 ...
- [POJ] 1274 The Perfect Stall(二分图最大匹配)
题目地址:http://poj.org/problem?id=1274 把每个奶牛ci向它喜欢的畜栏vi连边建图.那么求最大安排数就变成求二分图最大匹配数. #include<cstdio> ...
随机推荐
- Servlet-中文乱码
背景 从Tomcat5.x开始,GET,POST方法提交信息,Tomcat采用不同的方式来处理编码. 对于GET请求,Tomcat不会考虑使用request.setCharacterEncoding( ...
- xshell下载文件到本地/上传文件到服务器
xshell很好用,然后有时候想在windows和linux上传或下载某个文件,其实有个很简单的方法就是rz,sz首先你的Ubuntu需要安装rz.sz(如果没有安装请执行以下命令,安装完的请跳过.其 ...
- c#反射获取常量属性名以及其值(真正可用)
最近因为要开发rpc平台的c#客户端,其中部分常量类为了自动加载的map,需要反射解析出静态常量,往上搜了一堆,都各种的不靠谱. 亲自研究了下,如下: Type t = typeof(SpiderEr ...
- CSS应用内容补充及小实例
一.clear 清除浮动 <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...
- Android笔记——Android中数据的存储方式(二)
我们在实际开发中,有的时候需要储存或者备份比较复杂的数据.这些数据的特点是,内容多.结构大,比如短信备份等.我们知道SharedPreferences和Files(文本文件)储存这种数据会非常的没有效 ...
- 如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler)
本文讲述如何在 在SharePoint 2013/2010 解决方案中添加 ashx (HttpHandler). 一般处理程序(HttpHandler)是·NET众多web组件的一种,ashx是其扩 ...
- cocospods的安装与应用
安装cocospods 一,升级Ruby环境 ~ xxx$ sudo gem update --system 二,安装Cocoapods时需要访问cocoapods.org,该网站可能被墙掉,但是 ...
- C++ RTTI
一.定义:RTTI:Run Time Type Identification ,运行时类型识别:指程序能够使用基类的指针或引用来检索其所指对象的实际派生类型.二.使用方式:C++中有两个操作符提供RT ...
- CocoaPod出现-bash: pod: command not found 解决办法
从过年来到公司 就不用自己电脑了 之前一直自己带电脑 昨天随便建了一个demo 使用cocoapods 发现 -bash: pod: command not found 刚开 ...
- 编译iOS程序时的-all_load选项,以及-all_load 导致的 ld duplicate symbol xx的问题
在新的SDK环境中调试百度地图的应用程序时,app总是意外退出,找了半天发现错误的原因是unrecognized selector xx的错误,另外还有报了一个Unknown class XXX in ...