HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC. 最大匹配
来源:互联网 发布:电脑麦克风软件 编辑:程序博客网 时间:2024/04/30 16:31
转载请注明本文地址
题意:n个魔法师,m根魔杖,要配对,一人最多一根魔杖,一根魔杖最多配一个人。求最大匹配数。
思路:
裸最大匹配,不过题目有点长所以我直接开有道全文翻译了,看懂最后一段就可以了……
代码:
#include<iostream>#include<cstdio>#include<cstring>#include<cstdlib>#include<cmath>using namespace std;const int MAXV=110;int n,m;bool map[MAXV][MAXV],vis[MAXV];int match[MAXV];void init(){ memset(map,false,sizeof(map)); memset(match,-1,sizeof(match));}bool DFS(int u){ for(int v=0;v<n;v++) { if(map[u][v] && !vis[v]) { vis[v]=true; if(match[v]==-1 || DFS(match[v])) { match[v]=u; return true; } } } return false;}int hungary(){ int ans=0; for(int u=0;u<n;u++) { memset(vis,false,sizeof(vis)); if(DFS(u)) ans++; } return ans;}int main(){ while(scanf("%d%d",&n,&m)!=EOF) { init(); int num,t; for(int i=0;i<m;i++) { scanf("%d",&num); for(int j=0;j<num;j++) { scanf("%d",&t); t--; map[i][t]=true; } } printf("%d\n",hungary()); } return 0;}
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC. 最大匹配
- hdu 1179 Ollivanders: Makers of Fine Wands since 382 BC. (最大匹配)
- HDU 1179--Ollivanders Makers of Fine Wands since 382 BC【二分图的最大匹配】
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(最大匹配)
- hdu 1179 Ollivanders: Makers of Fine Wands since 382 BC.
- HDOj 题目1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图最大匹配)
- hdoj 1179 Ollivanders: Makers of Fine Wands since 382 BC. (二分图--最大匹配)
- hdu 1179 Ollivanders: Makers of Fine Wands since 382 BC. (二分匹配)
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC. 二分匹配(简单)
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC. 二分图匹配
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图匹配--匈牙利算法)
- HDU Problem 1179 Ollivanders: Makers of Fine Wands since 382 BC.【二分图匹配】
- HDU-1179-Ollivanders: Makers of Fine Wands since 382 BC.【二分匹配】【匈牙利算法】
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图匹配+匈牙利算法)
- hdoj 1179 Ollivanders: Makers of Fine Wands since 382 BC.
- hdu1179 Ollivanders: Makers of Fine Wands since 382 BC. (最大匹配)
- HPU1179 Ollivanders: Makers of Fine Wands since 382 BC.【二分图最大匹配】
- Hdoj 1179 Ollivanders: Makers of Fine Wands since 382 BC. 【二分匹配】
- ios的生命周期
- makefile
- Comparison of Architec…
- Java_全面总结Java泛型
- Java_泛型的理解与等价实现
- HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC. 最大匹配
- Java_List对象排序通用方法
- Java_int 和integer的区别
- Java_Object的使用
- Java_instanceOf
- java_instanceOf关键字
- javascript_使用MVVM模式(1):MVVM…
- Java_23种经典设计模式详解
- TypeScript_入门指南