POJ 1274 The Perfect Stall
来源:互联网 发布:c语言菜单设计模板 编辑:程序博客网 时间:2024/05/16 04:07
POJ 1274 The Perfect Stall
题目链接:POJ 1274
题意:
n个奶牛,m个帐篷。
n行,每行一个Si,表示第i个奶牛喜欢的帐篷个数,然后Si个数,表示第i个奶牛喜欢的帐篷号。
输出最多可以能够住在喜欢的帐篷的奶牛数。
分析:
二分匹配的模板
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>#include<cmath>#include<vector>using namespace std;const int maxn=512;bool used[maxn];vector<int>g[maxn];int L,R;int x[maxn],y[maxn];bool SearchPath(int u){int Size=g[u].size(),v; for(int i=0;i<Size;i++) { v=g[u][i]; if(!used[v]) { used[v] = true;if(y[v] == -1 || SearchPath(y[v])){ y[v]=u; x[u]=v; return true;} } } return false;}int MaxMatch(){ int ret=0; memset(x,-1,sizeof(x)); memset(y,-1,sizeof(y)); for(int u=1;u<=L;u++) {if(x[u]==-1){ memset(used,false,sizeof(used));if(SearchPath(u)) ret++;} } return ret;}int main(){// freopen("in.txt","r",stdin);int n,m,cnt,p;while(scanf("%d %d",&n,&m)!=EOF){for(int i=1;i<=n;i++){g[i].clear();scanf("%d",&cnt);for(int j=1;j<=cnt;j++){scanf("%d",&p);g[i].push_back(p);}}L=n;R=m;printf("%d\n",MaxMatch());}return 0;}
0 0
- 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 1274The 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
- 事件分发机制
- Info 2015-5-25 20:22:34
- android加速度传感器数据存储到txt中
- Hadoop 的一些资料总结,动态更新....
- 拓扑排序
- POJ 1274 The Perfect Stall
- Could not allocate CursorWindow size due to error -12 错误解决方法
- log4cxx在linux下的编译使用
- Hadoop小程序测试方法
- MySQL安装
- Cocos2d-x 多分辨率适配完全解析
- PHP Filter 函数中文注解
- Double Check形式的单例模式
- Android 中对于图片的内存优化方法