hdu 1179 最大匹配


题意:n个ren m个棍子 每个棍子可以与i个人结合 问最大有多少个结合
#include<iostream>
#include<cmath>
using namespace std;
int map[111][111];
int fa[111];
int v[111];
int n,m;
int dfs(int x)
{
for(int i=1;i<=n;i++)
{
if(map[x][i]&&!v[i])//回溯时i不能再匹配
{
v[i]=1;
if(!fa[i]||dfs(fa[i]))
{
fa[i]=x;
return 1;
}
}
}
return 0;
}
int main()
{
int sum,i,t,x;
while(scanf("%d%d",&n,&m)!=EOF)
{
memset(map,0,sizeof(map));
for(i=1;i<=m;i++)
{
scanf("%d",&t);
while(t--)
{
scanf("%d",&x);
map[i][x]=1;
}
}
sum=0;
memset(fa,0,sizeof(fa));
for(i=1;i<=m;i++)
{
memset(v,0,sizeof(v));
if(dfs(i))
sum++;
}
printf("%d\n",sum);
}
return 0;
}

hdu 1179 最大匹配,码迷,mamicode.com

时间: 2024-08-06 03:44:57

hdu 1179 最大匹配的相关文章

hdu 1083 最大匹配

题意:N个学生 P 个课程  求最大匹配 3 3 //学生 课程 3 1 2 3 //课程1 匹配学生1 2 3 2 1 2 1 1典型的匹配没什么好说的 ? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 #include<iostream

HDU 2853 最大匹配&amp;KM模板

http://acm.hdu.edu.cn/showproblem.php?pid=2853 这道题初看了没有思路,一直想的用网络流如何解决 参考了潘大神牌题解才懂的 最大匹配问题KM 还需要一些技巧来解决最小变动, 做法是:把原先的邻接矩阵每个数扩大k倍(k>n) 为了突出原先的选择,也就是同等情况下优先选择原来的方案 给原来的方案对应矩阵内的数据+1 那么 最终得出的最大匹配值/k=真实的最大匹配 最终得出的最大匹配值%k=原来的方案采用了几个 这里的KM留下来做模板 /* 二分图最佳匹配

HDU——1179 Ollivanders: Makers of Fine Wands since 382 BC.

Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/65536 K (Java/Others)Total Submission(s): 1895    Accepted Submission(s): 1084 Problem Description In Diagon Alley ,there is only one Wand-

HDU 2063 最大匹配的基础题

中文题,题目大意不说了. 思路:就是寻找最大匹配,最大匹配就是每次找增广路,如果存在增广,那就把增广路上面的边全部都翻转即可.这样说明能多匹配一个,+1即可. //看看会不会爆int!数组会不会少了一维! //取物问题一定要小心先手胜利的条件 #include <bits/stdc++.h> using namespace std; #define LL long long #define ALL(a) a.begin(), a.end() #define pb push_back #defi

hdu 3729 最大匹配

此题是我AC的HDU的201道题目.泪流满面啊! 字典序最大(最小)真是个烦人的东西. 学生i与其对应的分数区间的每个点连一条边.字典序最大,编号最大的学生开始匹配. HK无法AC啊,试了很久.我不会说,能过样例. 最后用了DFS版的匈牙利算法过了.人们说这个代码简洁.不过我一般都用HK,时间复杂度低.今天发现了这个,还是有收获的.下次什么字典序,就用匈牙利. 1 #include<iostream> 2 #include<cstdio> 3 #include<cstring

HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(匈牙利算法)

Problem Description In Diagon Alley ,there is only one Wand-seller,peeling gold letters over the door read Ollivanders: Makers of Fine Wands since 382 BC.A single wand lay on a faded purple cushion in the dusty window. A tinkling bell rang somewhere

HDU 1179 Ollivanders: Makers of Fine Wands since 382 BC.(二分图匹配--匈牙利算法)

Ollivanders: Makers of Fine Wands since 382 BC. Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 131072/65536 K (Java/Others) Total Submission(s): 1314 Accepted Submission(s): 718 Problem Description In Diagon Alley ,there is only one Wand-seller

UVALive 5033 I&#39;m Telling the Truth 二分图最大匹配(略有修改)

I - I'm Telling the Truth Time Limit:3000MS     Memory Limit:0KB     64bit IO Format:%lld & %llu Submit Status Practice UVALive 5033 Description After this year's college-entrance exam, the teacher did a survey in his class on students' score. There

二分图练习小结

1. HDU 1151 Air Raid 题目描述有点长,就是说一个有向无环图,最少需要走几次能把整张图上的边遍历.典型的最小路径覆盖,答案就是顶点数-最大匹配数 #include <set> #include <map> #include <list> #include <stack> #include <queue> #include <ctime> #include <cmath> #include <cstd