poj 1274The Perfect Stall
来源:互联网 发布:北京云计算招聘 编辑:程序博客网 时间:2024/04/30 20:10
第一次接触二分图匹配。
这题是一个匈牙利算法的模板题直接套就行。
题意是 给你奶牛和谷仓的个数a和b,接下来a行是奶牛喜欢去的谷仓。第一个是谷仓个数,接下来是谷仓编号。
这里我们把行当奶牛,列当谷仓。
在套模板。。ok;
#include<Stdio.h>#include<string.h>int map[1005][1005];int a,b,link[1005],use[1005];int dfs(int cap){int i,j;for(i=1;i<=b;i++){if(map[cap][i]&&!use[i]){use[i]=1;j=link[i];link[i]=cap;if(j==-1||dfs(j))return 1;link[i]=j;}}return 0;}int hungary(){int num=0;int i,j;memset(link,-1,sizeof(link));for(i=1;i<=a;i++){for(j=1;j<=b;j++){use[j]=0;}if(dfs(i))num++;}return num;}int main(){int i,j,c,d;while(~scanf("%d %d",&a,&b)){memset(map,0,sizeof(map));for(i=1;i<=a;i++){scanf("%d",&c);for(j=1;j<=c;j++){scanf("%d",&d);map[i][d]=1;}}printf("%d\n",hungary());}return 0;}
1 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
- 重构Button类,实现APP在大屏幕下用遥控器遥控,界面按钮在获取焦点下显示边框
- POJ 1080 Humman Gene Function
- 64、使用jQuery全局函数转换数组
- document.createElement()的用法
- hdu 2063 过山车
- poj 1274The Perfect Stall
- html,css等入门
- poj 1274The Perfect Stall(二分最大匹配法——匈牙利算法)
- INSTALL_FAILED_UID_CHANGED解决办法
- FatMouse's Speed
- 修改hadoop的DBInputFormat类,实现一次读取多个数据库
- asp.net中TabContainer的静态使用方法
- mybatis if 条件判断 = like
- 测试用例--QC中写的测试用例