POJ-1274 The Perfect Stall(二分图最大匹配)
来源:互联网 发布:哪个软件可以看陆小凤 编辑:程序博客网 时间:2024/05/19 03:22
题目:POJ-1274 The Perfect Stall
题目大意:就是一个农场主有n头牛,每头牛都有特定的产奶牛棚,一共m个牛棚,现在告诉你每个牛会在哪个棚子里面产奶,问:最多能有多少头牛正常产奶。
解题思路:也是一道裸的二分图最大匹配,就是为牛选棚子,了解了原理,很快ac。
AC代码:
#include<iostream>
#include<string.h>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<vector>
using namespace std;
int n,m;
vector<int>map[210];
bool visit[210];
int cx[210];
int cy[210];
bool dfs(int x){
int i,j;
for (i=0;i<map[x].size();i++){
j=map[x][i];
if (visit[j]==0){
visit[j]=1;
if (cy[j]==-1||dfs(cy[j])){
cy[j]=x;
cx[x]=i;
return 1;
}
}
}
return 0;
}
int maxmatch(){
int i,j,ans=0;
memset (cx,-1,sizeof(cx));
memset (cy,-1,sizeof(cy));
for (i=0;i<n;i++){
if (cx[i]==-1){
memset (visit,0,sizeof(visit));
ans+=dfs(i);
}
}
return ans;
}
int main(){
int i,j,x,y;
while (scanf("%d%d",&n,&m)!=EOF){
for (i=0;i<n;i++){
map[i].clear();
}
for (i=0;i<n;i++){
scanf("%d",&x);
while (x--){
scanf("%d",&y);
map[i].push_back(y);
}
}
printf("%d\n",maxmatch());
}
}
- POJ 1274The Perfect Stall(二分图最大匹配)
- poj The Perfect Stall 1274 (二分图最大匹配)
- POJ-1274 The Perfect Stall(二分图最大匹配)
- POJ 1274 The Perfect Stall 二分图最大匹配
- 二分图最大基数匹配 POJ 1274 The Perfect Stall
- POJ 1274 The Perfect Stall(二分图最大匹配)
- 【二分图+最大匹配】北大 poj 1274 The Perfect Stall
- Poj 1274 The Perfect Stall[二分图最大匹配]
- POJ 1274 The Perfect Stall 二分图最大匹配
- POJ 1274 The Perfect Stall(二分图最大匹配)
- POJ 1274-The Perfect Stall(二分图_最大匹配)
- POJ - 1274 The Perfect Stall 二分图 最大匹配
- POJ 1274 The Perfect Stall(二分图最大匹配)
- POJ 1274 The Perfect Stall(最大二分图匹配)
- POJ 1274 The Perfect Stall(二分图最大匹配)
- POJ 1274 The Perfect Stall(二分图匹配)
- POJ 题目1274 The Perfect Stall(二分图最大匹配)
- POJ 1274-The Perfect Stall(二分图匹配/最大流问题)
- Springmvc 陷阱
- Leetcode 739. Daily Temperatures
- coursera deep learning course2 week3
- 开发中自己遇到的问题和大家分享一下java.io.IOException: tmpFile.renameTo(classFile) failed and(和) failed (2: No suc
- 第十六周Java网络编程
- POJ-1274 The Perfect Stall(二分图最大匹配)
- win10 关闭 取消 开机登录密码
- Spring框架的实现
- 项目三 负数把正数赶出队列
- 匆匆忙忙的我又来了
- easyui
- Channel Pruning for Accelerating Very Deep Neural Networks代码详解
- 2017NOIP小结
- win10 关闭 任务栏 操作中心 通知栏 图标