Tag: class sum output panel code CST get turn input
< topic links >
RPG Girls today and we go to the amusement park to play, finally can sit on the dream of the roller coaster. However, the roller coaster in each row only two seats, and there is an unwritten rule, is that every girl must find all the boys do partner and her sitting. However, each girl has their own ideas, for example, rabbit only willing and xhd or pqk do Partner,grass only willing and linle or ll do partner,princesssnow willing and water prodigal or pseudo-queer do partner. Considering the financial problems, boss Liu decided to only find partner people to ride the roller coaster, other people, hey, just stand down and watch it. Smart Acmer, can you help calculate the maximum number of pairs can be on the roller coaster?
Input
The first line of input data is three integers k, M, N, respectively, indicating the number of possible combinations, the number of females, and the number of males. 0<k<=1000
1<=n and m<=500. The next K-line, each line has two numbers, respectively, the female AI is willing to and boys BJ do partner. Last 0 end input.
Output
For each set of data, output an integer that represents the maximum number of combinations that can be seated on a roller coaster.
Sample Input
6 3 31 11 21 32 12 33 10
Sample Output
3
Problem Solving Analysis:
The Hungarian algorithm in binary graph matching does not understand Hungarian algorithm to see this blog >>>
To figure out the recursive process in the find[] array in the code below, you can manually simulate the process yourself.
#include <cstdio>#include<cstring>Const intmaxn= -+ -;intK,m,n;intLINE[MAXN][MAXN],BOY[MAXN],USED[MAXN];BOOLFindintx) { for(intI=1; i<=m;i++) {//Traverse All selected persons if(Line[x][i]&&!used[i]) {//if X is favorable to I and is not selected at this recursive selection stage (even if it is temporarily selected, the new recursion may change)used[i]=1;//tag is selected if(!boy[i]| | Find (Boy[i])) {//if the chosen person does not belong or his affiliation can be reversed (his attribution can choose other selected persons)Boy[i]=x;//Set the attribution to x return true; } } } return false;}intMain () { while(SCANF ("%d%d%d", &k,&n,&m)! =eof,k) {memset (line,0,sizeof(line)); memset (Boy,0,sizeof(boy)); for(intI=0; i<k;i++){ intx, y; scanf ("%d%d",&x,&y); Line[x][y]=1;//indicates that X wants to have a relationship with Y } intsum=0;//record pairs of couples that can be paired for(intI=1; i<=n;i++) {memset (used,0,sizeof(used));//used array Remember to clear 0 every time if(Find (i)) sum++; } printf ("%d\n", sum); } return 0;}
2018-08-13
HDU 2063 roller coaster "Hungarian Algorithm" (classic)