HDU-2255 Ben-off make a lot of money (binary chart, km algorithm, template)

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): 10394 Accepted Submission (s): 4617


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 Input2100 1015 23

Sample Output123

Sourcehdoj Summer Exercise (4)-Buffet Dinner

Recommendlcy

Title: Literal meaning.

Problem-Solving ideas: Use the village name as the left, the house as the right, the village name to the profit of the house as side, km template directly with the line. (Here is a very detailed explanation, I will not repeat it.) http://www.cnblogs.com/jackge/archive/2013/05/03/3057028.html)

#include <cstdio>#include<cstring>#include<algorithm>using namespacestd;Const intmaxn=305;Const intinf=0x3f3f3f3f;intLINE[MAXN][MAXN];intEX_B[MAXN];intEX_G[MAXN];BOOLVIS_B[MAXN];BOOLVIS_G[MAXN];intN,MATCH[MAXN],SLACK[MAXN];BOOLDfsintx) {Vis_g[x]=true;  for(intI=0; i<n;i++)    {        if(Vis_b[i])Continue; inttemp = ex_g[x]+ex_b[i]-Line[x][i]; if(temp==0) {Vis_b[i]=true; if(match[i]==-1||DFS (Match[i])) {Match[i]=x; return true; }        }        Else{Slack[i]=min (slack[i], temp); }    }    return false;}intkm () {memset (match,-1,sizeof(match)); memset (Ex_b,0,sizeof(Ex_b));  for(intI=0; i<n;i++) {Ex_g[i]=line[i][0];  for(intj=1; j<n;j++) Ex_g[i]=Max (line[i][j],ex_g[i]); }     for(intI=0; i<n;i++) {Fill (Slack,slack+N,inf);  while(1) {memset (Vis_g,false,sizeof(Vis_g)); memset (Vis_b,false,sizeof(Vis_b)); if(Dfs (i)) Break; intD=INF;  for(intj=0; j<n;j++)                if(vis_b[j]==false) {D=min (d,slack[j]); }             for(intj=0; j<n;j++)            {                if(Vis_g[j]) ex_g[j]-=D; if(Vis_b[j]) ex_b[j]+=D; ElseSlack[j]-=D; }        }    }    intRET =0;  for(intI=0; i<n;i++) {ret+=Line[match[i]][i]; }    returnret;}intMain () { while(SCANF ("%d", &n)! =EOF) {         for(intI=0; i<n;i++)        {             for(intj=0; j<n;j++) {scanf ("%d",&Line[i][j]); }} printf ("%d\n", km ()); }}

HDU-2255 Ben-off make a lot of money (binary chart, km algorithm, template)

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.