The Perfect Stall(最大二分匹配)
来源:互联网 发布:h3c vlan 添加端口 编辑:程序博客网 时间:2024/06/05 00:28
Link:http://poj.org/problem?id=1274
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 52 2 53 2 3 42 1 53 1 2 51 2
Sample Output
4
Source
My code:
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
const int maxn=500;
vector<int>map[maxn];
int match[maxn],n,m,ans;
bool vis[maxn];
bool dfs(int u)
{
for(int i=0;i<map[u].size();i++)
{
if(!vis[map[u][i]])
{
vis[map[u][i]]=true;
if(match[map[u][i]]==-1||dfs(match[map[u][i]]))
{
match[map[u][i]]=u;
return true;
}
}
}
return false;
}
void hangry()
{
ans=0;
memset(match,-1,sizeof(match));
for(int i=1;i<=n;i++)
{
memset(vis,false,sizeof(vis));
if(dfs(i))
ans++;
}
}
int main()
{
int s,v;
while(scanf("%d%d",&n,&m)==2)
{
for(int i=0;i<maxn;i++)
map[i].clear();
for(i=1;i<=n;i++)
{
scanf("%d",&s);
while(s--)
{
scanf("%d",&v);
map[i].push_back(v);
}
}
hangry();
printf("%d\n",ans);
}
return 0;
}
- The Perfect Stall(最大二分匹配)
- (二分图最大匹配)The Perfect Stall
- POJ 1274The Perfect Stall(二分图最大匹配)
- The Perfect Stall(二分图最大匹配)
- poj1274 The Perfect Stall(二分图匹配 / 最大流)
- poj The Perfect Stall 1274 (二分图最大匹配)
- POJ-1274 The Perfect Stall(二分图最大匹配)
- usaco 4.2 The Perfect Stall 二分图最大匹配
- POJ 1274 The Perfect Stall(最大二分匹配)
- POJ 1274 The Perfect Stall 二分图最大匹配
- 二分图最大基数匹配 POJ 1274 The Perfect Stall
- POJ1274 The Perfect Stall 简单最大二分匹配
- POJ1274 The Perfect Stall [二分图最大匹配 匈牙利算法]
- POJ 1274 The Perfect Stall(二分图最大匹配)
- 【二分图+最大匹配】北大 poj 1274 The Perfect Stall
- USCAO4.2 The Perfect Stall ,二分图最大匹配
- Poj 1274 The Perfect Stall[二分图最大匹配]
- POJ 1274 The Perfect Stall 二分图最大匹配
- 求子数组的最大和要求O(n)
- 添加表格的右侧索引
- aptana的使用
- selenium抓取页面可用元素css
- java socket编程
- The Perfect Stall(最大二分匹配)
- 按钮 只响应一个
- 【2012noi国家队】Day 1 Day2 by sevenkplus
- 黑马程序员 java学习笔记 Day1:异常
- jstl api
- 新版tigase配置文档地址有关
- 程序员选择公司的8个标准
- Android WebView缓存策略详解
- 关于equals方法