POJ 1274 The Perfect Stall(二分匹配-hungary)
来源:互联网 发布:小松菜奈穿衣 知乎 编辑:程序博客网 时间:2024/05/16 13:55
Description
有n头奶牛,每头奶牛都有自己喜欢的几个谷仓,每个谷仓只能供应一头奶牛进食,问最多能有多少头奶牛可以去自己喜欢的谷仓吃食物
Input
第一行为两个整数n和m分别表示奶牛数和谷仓数,之后n行每行首先输入一个整数num表示该头奶牛喜欢的谷仓数,之后num个整数表示这个奶牛的喜欢的谷仓编号
Output
输出最多能有多少头奶牛可以吃到食物
Sample Input
5 5
2 2 5
3 2 3 4
2 1 5
3 1 2 5
1 2
Sample Output
4
Solution
二分匹配裸题,直接套模版
Code
#include<cstdio>#include<iostream>#include<cstring>using namespace std;#define maxn 222int uN,vN;int g[maxn][maxn];int linker[maxn];bool used[maxn];bool dfs(int u){ int v; for(v=0;v<vN;v++) if(g[u][v]&&!used[v]) { used[v]=true; if(linker[v]==-1||dfs(linker[v])) { linker[v]=u; return true; } } return false; } int hungary(){ int res=0; int u; memset(linker,-1,sizeof(linker)); for(u=0;u<uN;u++) { memset(used,0,sizeof(used)); if(dfs(u)) res++; } return res; } int main(){ while(~scanf("%d%d",&uN,&vN)) { memset(g,0,sizeof(g)); for(int i=0;i<uN;i++) { int num,j; scanf("%d",&num); while(num--) { scanf("%d",&j); g[i][j-1]=1; } } int ans=hungary(); printf("%d\n",ans); } return 0;}
0 0
- POJ 1274 The Perfect Stall(二分匹配-hungary)
- 【POJ】1274 The Perfect Stall 二分匹配
- Poj 1274 The Perfect Stall【二分匹配】
- POJ 1274 The Perfect Stall(二分匹配)
- POJ 1274 The Perfect Stall(二分匹配)- from lanshui_Yang
- POJ 1274The Perfect Stall(二分图最大匹配)
- POJ 1274 The 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 (二分图匹配)
- linux kernel -- intcall
- 虚拟机CentOS6.3环境下配置ip地址(慕课学习笔记)
- Android ViewPager Parallax视觉差切换动画
- IOS 程序执行
- java中的反射
- POJ 1274 The Perfect Stall(二分匹配-hungary)
- Liquidfun的编译与运行
- Android 之 注解
- 【斜率DP】BZOJ 1911:特别行动队
- PopWindow 添加背景以及设置背景和popwindow进入进出动画
- 在Hibernate工程中如何让数据库从MYSQL换成ORACLE
- 自定义MaterialProgressBarSupport
- DruidDataSource配置 阿里数据源
- 常用编码总结