Roller coaster
Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 11142 accepted submission (s): 4912
Problem descriptionrpg girls went to the playground today and finally got on the coveted roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule, that is, every girl must find a boy as a partner and sit with her. However, every girl has her own ideas. For example, rabbit is only willing to be a partner with xhd or pqk. Grass is only willing to be a partner with linle or ll, princesssnow is willing to be a partner with the water prodigal son or pseudo cool. Considering the funding issue, boss Liu decided to let the partner find a ride on the roller coaster. Other people, hey, just stand and watch it. Smart acmer, can you help calculate how many combinations can ride on a roller coaster?
The first line of input data is a three integer K, M, N, indicating the number of possible combinations, the number of girls, and the number of boys. 0 <k <= 1000
1 <= N and M <= 500. In the next K rows, each row has two numbers, indicating that female AI is willing to be partner with boys' BJ. The last 0 end input.
Output outputs an integer for each group of data, indicating the maximum number of combinations that can be used on a roller coaster.
Sample Input
6 3 31 11 21 32 12 33 10
Sample output
3
Authorprincesssnow
Sourcerpg session exercise Second Matching template questions, reference materials http://blog.csdn.net/q3498233/article/details/5786225
# Include <iostream> # include <cstdio> # include <cstring> using namespace STD; const int MX = 510; int NV, Nan; bool G [MX] [MX]; // int link [MX]; // link [y] indicates the x node bool Pd [MX] adjacent to the Y node. // auxiliary array bool work (int x) {for (INT I = 1; I <= Nan; I ++) // enumerate boys {If (G [x] [I] &! Pd [I]) // This boy is the person she wants and is not with others {Pd [I] = true; // mark if (link [I] =-1 | work (link [I]) together. // if the boy does not find an object, or a girl with a boy can change the object {link [I] = x; return true ;}}return false ;}int main () {int m; while (scanf ("% d", & M )! = EOF) {If (M = 0) break; scanf ("% d", & NV, & Nan); int A, B, I, J, K, ans = 0; memset (G, 0, sizeof g); memset (link,-1, sizeof link); for (I = 0; I <m; I ++) {scanf ("% d", & A, & B); G [a] [B] = true;} for (I = 1; I <= NV; I ++) // enumerative female {memset (PD, 0, sizeof PD); If (Work (I) // if it can match {ans ++ ;}} printf ("% d \ n", ANS);} return 0 ;}
Hdu2063 roller coaster