HDU 2063 roller coaster The maximum matching template for the two-part chart: Feel the template code is very concise

Source: Internet
Author: User

Roller coasterTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 13092 Accepted Submission (s): 5746


Problem DESCRIPTIONRPG 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?
The first line of input data is three integers k, M, N, each representing the number of possible combinations, the number of girls, 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, outputs 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
Template code I've been watching for a long time. Code:
#include <stdio.h> #include <string.h> #define SIZE 550int pre[size]; int k, M, N; bool Vis[size], graph[size ][size]; int find (int pos) {for (int i = 0; I <= N; ++i) {if (!vis[i] && graph[pos][i]) {vis[i] = true; if (Pre[i] = =-1 | | Find (Pre[i])) {pre[i] = pos; return 1;}} return 0;} int main () {while (~SCANF ("%d", &k) && k) {scanf ("%d%d", &m,&n), memset (pre,-1,sizeof (pre)); Memset ( Graph,false,sizeof (graph)); for (int i = 0; i < K; ++i) {int x, y; scanf ("%d%d", &x,&y); Graph[x][y] = true;} int sum = 0; for (int i = 1; I <= m; ++i) {memset (vis,false,sizeof (VIS)); sum + = find (i);} printf ("%d\n", sum);} return 0;}

with June

HDU 2063 roller coaster The maximum matching template for the two-part chart: Feel the template code is very concise

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.