Ben-off make money (km)

Source: Internet
Author: User

Ben-off make a lot of money

Time limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others) total submission (s): 5865 Accepted Submission (s): 2589

Problem description legend in a faraway place there is a very wealthy village, one day the village chief decided to reform the system: redistribute the House. This is a big event, related to people's housing problems ah. There are n rooms in the village, just there are n common people, considering every house to have a room to live (if there are people do not live, easy to cause instability factors), each family must be assigned to a house and can only get a house. On the other hand, village chiefs and other village leaders hope to get the most benefit, so that the village's institutions will be rich. Because people are richer, they can have a certain price for each house in their economy, for example, there are 3 houses, and a common man can give 100,000 to the first, 20,000 to the 2nd. 200,000 for the 3rd room. (in their economy, of course). The question now is how village leaders can allocate their homes to make the most of their income. (Villagers who have the money to buy a house but not necessarily can buy it depends on what the village leader assigns). Input data contains multiple sets of test cases, the first row of each set of data input n, indicating the number of houses (also the number of people home), followed by n rows, the number of n per row represents the price of the room of the second village name (n<=300). Output make the maximum revenue value for each set of data, one row for each set of outputs. Sample Input2 Output123: The maximum weight matching of two graphs, km algorithm template; code:
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 using namespacestd;6 #defineMem (x, y) memset (x,y,sizeof (x))7 Const intmaxn=310;8 Const intinf=0x3f3f3f3f;9 intMAT[MAXN],MP[MAXN][MAXN],LX[MAXN],LY[MAXN];Ten intUSDX[MAXN],USDY[MAXN]; One intN; A BOOLDfsintx) { -usdx[x]=1; -      for(intI=1; i<=n;i++){ the         if(!usdy[i]&&lx[x]+ly[i]==mp[x][i]) {//Note that this is X . -usdy[i]=1; -             if(!mat[i]| |DFS (Mat[i])) { -Mat[i]=x;return true; +             } -         } +     } A     return false; at } - intkm () { -Mem (Mat,0); Mem (LX,0); Mem (ly,0); -      for(intI=1; i<=n;i++) -      for(intj=1; j<=n;j++) -lx[i]=Max (lx[i],mp[i][j]); in      for(intI=1; i<=n;i++){ -Mem (USDX,0); Mem (Usdy,0); to          while(!DFS (i)) { +             intD=INF; -              for(intj=1; j<=n;j++) the             if(Usdx[j]) *              for(intk=1; k<=n;k++) $                 if(!Usdy[k])Panax NotoginsengD=min (D,lx[j]+ly[k]-mp[j][k]);//Note that this is K . -              for(intj=1; j<=n;j++){ the                 if(Usdx[j]) lx[j]-=D; +                 if(Usdy[j]) ly[j]+=D; A             } theMem (USDX,0); Mem (Usdy,0); +         } -     } $     intans=0; $      for(intI=1; i<=n;i++) ans+=lx[i]+Ly[i]; -     returnans; - } the intMain () { -      while(~SCANF ("%d",&N)) {WuyiMEM (MP,0); the          for(intI=1; i<=n;i++) -              for(intj=1; j<=n;j++) Wuscanf"%d",&mp[i][j]); -printf"%d\n", km ()); About     } $     return 0; -}

Ben-off make money (km)

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.