Test Instructions: There are n elective courses, M with classmates, now tell you the members of each course, to choose a representative from each of the members of the course, a classmate can only represent an elective course, the maximum number of delegates. key: The Hungarian algorithm, the core algorithmCODE:
/*Author:JDDPROG:rqnoj140 looking for representative meta date:2015.9.28*/#include<cstdio>#include<cstring>#defineREP (i, S, N) for (int i = s; i <= n; i + +)#defineRep_ (i, S, N) for (int i = n; i >= s; i-)#defineMax_n 205using namespacestd;intN, M, G[max_n], map[max_n][max_n];BOOLUsed[max_n];voidinit () {scanf ("%d%d", &n, &m); memset (Map,0,sizeof(map)); REP (i,1, N) { intX scanf"%d", &x); while(X! =0) Map[i][x] =1, scanf ("%d", &x); } }BOOLFindintx) {REP (i,1, M) { if(!used[i] &&Map[x][i]) {Used[i]=1; if(! G[i] | |find (G[i])) {G[i]=x; return 1; } } } return 0;}voiddoit () {memset (G,0,sizeof(G)); intAns =0; REP (i,1, N) {memset (used,0,sizeof(used)); if(Find (i)) ans + +; } printf ("%d\n", ans);}intMain () {init (); Doit (); return 0;}
RQNOJ141 looking for Representative yuan