Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=2063
Binary matching maximum match number simple problem, Hungarian algorithm. Learning binary Matching Portal: http://blog.csdn.net/dark_scope/article/details/8880547
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <vector>5 using namespacestd;6 Const intN = 1e3 +5;7 structEdge {8 intto, next;9 }edge[n];Ten intHead[n], match[n], CNT;//Match Right collection corresponds to the number of the left collection One BOOLVis[n]; A - voidinit () { -Memset (Head,-1,sizeof(head)); thememset (Match,0,sizeof(Match)); -CNT =0; - } - +InlinevoidAddintU,intv) { -Edge[cnt].next =Head[u]; +Edge[cnt].to =v; AHead[u] = cnt++; at } - - BOOLDfsintu) { - for(inti = Head[u]; ~i; i =Edge[i].next) { - intv =edge[i].to; - if(!vis[v]) {//not found. inVIS[V] =true; - if(!match[v] | | DFS (MATCH[V)) {//no match or try to make room for a match . toMATCH[V] =u; + return true;//Match Success - } the } * } $ return false;Panax Notoginseng } - the intHungry (intN) { + intres =0; A for(inti =1; I <= N; ++i) { thememset (Vis,false,sizeof(Vis)); + if(Dfs (i)) -res++; $ } $ returnRes; - } - the intMain () - {Wuyi intk, N, M, U, v; the while(~SCANF ("%d", &k) &&k) { -scanf"%d%d", &n, &m); Wu init (); - for(inti =0; I < K; ++i) { Aboutscanf"%d%d", &u, &v); $ Add (U, v); - } -printf"%d\n", Hungry (n)); - } A return 0; +}
HDU 2063 roller coaster (binary matching primer)