Roller coaster
Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 11509 Accepted Submission (s): 5066
Problem DESCRIPTIONRPG girls today and everyone to the amusement park to play, finally can sit on the dream of the roller coaster. However, there are only two seats in each row of the roller coaster, and there is an unwritten rule that every girl must find a boy to do partner and sit with her. However, every girl has their own ideas, for example, rabbit just willing and xhd or pqk do partner,grass just 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 just let people find partner to ride the roller coaster, other people, hehe, stand in the following look at it. Smart Acmer, can you help calculate the maximum number of combinations that can be on a 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
Authorprincesssnow
SOURCERPG Practice Competition
Problem Solving Ideas:
It feels like the Hungarian algorithm is similar to the algorithm for maximum flow, and each time it goes to the augmented path to get a lot of other "returns".
This blog post is very interesting http://blog.csdn.net/dark_scope/article/details/8880547 very easy to understand the Hungarian algorithm.
Code:
#include <iostream> #include <stdio.h> #include <algorithm> #include <string.h>using namespace std;const int maxn=502;int k,m,n;int g[maxn][maxn];//adjacency matrix to store edge int linked[maxn];//point to the right and which point to the left matches bool Vis[maxn];bool DFS ( int u) {for (int v=1;v<=n;v++) {if (G[u][v]&&!vis[v]) {vis[v]=1; if (!linked[v]| | DFS (LINKED[V])//male V has not been matched or the front girl can choose other boys so that the girl u can match boys v {linked[v]=u; return true; }}} return false;} int Hungary () {int ans=0; memset (linked,0,sizeof (linked)); for (int u=1;u<=m;u++) {memset (vis,0,sizeof (VIS)); if (DFS (U)) ans++; } return ans; int main () {while (scanf ("%d", &k)!=eof&&k) {scanf ("%d%d", &m,&n); memset (G,0,sizeof (g)); int l,r; for (int i=1;i<=k;i++) {scanf ("%d%d", &l,&r); G[l][r]=1; } printf ("%d\n",Hungary ()); } return 0;}
[ACM] HDU 2063 roller coaster (binary chart, Hungarian algorithm)