POJ1274
来源:互联网 发布:达内可靠吗 知乎 编辑:程序博客网 时间:2024/05/29 17:24
Problem: The Perfect Stall
Description: 给奶牛挤牛奶,一个挤奶工只能给一头奶牛挤奶,一头奶牛也只能由一位挤奶工挤奶,现在,给出挤奶工能挤奶的牛的情况,问你最多有几头奶牛能成功挤奶。
Solution: 二分图的最大匹配。很经典的题目,用来练习匈牙利算法。
Code(C++):
#include <iostream>#include <vector>#include <string.h>using namespace std;const int M=200+5;bool mat[M][M];bool used[M];int belong[M];int n,m;vector<int> to[M];bool dfs(int s){ for(int i=0;i<to[s].size();i++){ int end=to[s].at(i); if(used[end]) continue; used[end]=true; if(belong[end]==-1||dfs(belong[end])){ belong[end]=s; return true; } } return false;}int main(){ while(cin>>n>>m){ for(int i=0;i<M;i++) to[i].clear(), belong[i]=-1; for(int i=1;i<=n;i++){ int num,x; cin>>num; while(num--) cin>>x, to[i].push_back(x); } int ans=0; for(int i=1;i<=n;i++){ memset(used,false,sizeof(used)); if(dfs(i)) ++ans; } cout<<ans<<endl; } return 0;}
0 0
- poj1274
- poj1274
- poj1274
- poj1274
- poj1274
- poj1274
- POJ1274
- POJ1274 The Perfect Stall
- POJ1274 The Perfect Stall
- poj1274 二分图
- poj1274 最大二分匹配
- poj1274 - The Perfect Stall
- poj1274 匈牙利算法
- poj1274 The Perfect Stall
- 二分图片匹配--poj1274
- POJ1274-二分匹配
- POJ1274 The Perfect Stall
- POJ1274(多重背包)
- 二叉树的先序中序后序遍历 (递归和非递归)
- ORA-00054: 资源正忙,但指定以 NOWAIT 方式获取资源
- CXF WebService整合Spring
- hibernate分页查询
- Node.js 安装配置
- POJ1274
- Node.js 教程
- Skyboxes
- 年薪百万的年轻人都是怎样生活的?——脸书程序员的故事
- Linux常用命令大全
- HIVE和HBASE区别
- Node.js 创建第一个应用
- Jfinal 集成spring 、cxf 做webService服务
- zcuSHbuD2Wn3.exe