HDU2255 Ben-off make money (km template problem)

Source: Internet
Author: User

Description

Legend has it that in faraway places there is a very wealthy village, and 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

The input data contains multiple sets of test cases, the first line of each set of data entered N, indicating the number of houses (also the number of people in the home), followed by n rows, the number of n per row represents the first village name of the room price (n<=300).

Output

Please output the maximum revenue value for each set of data, one row for each group of outputs.

Sample Input

2 100 10) 15 23

Sample Output

123 template questions, organize the template
/************************************************author:d evilcreated time:2016/5/25 16:58:45***************** ******************************* */#include<cstdio>#include<cstring>#include<iostream>#include<algorithm>#include<vector>#include<queue>#include<Set>#include<map>#include<string>#include<cmath>#include<stdlib.h>using namespacestd;Const intn=301;Const intinf=0x3f3f3f3f;intW[n][n];intLx[n],ly[n];intLink[n];intVisx[n],visy[n];intSlack[n];intN;BOOLDfsintu) {Visx[u]=1;  for(intv=1; v<=n;v++)    {        if(Visy[v])Continue; inttmp=lx[u]+ly[v]-W[u][v]; if(!tmp) {Visy[v]=1; if(link[v]==-1||DFS (Link[v])) {Link[v]=T; return 1; }        }        Else if(slack[v]>tmp) slack[v]=tmp; }    return 0;}intkm () {memset (link,-1,sizeof(link)); memset (ly,0,sizeof(ly));  for(intI=1; i<=n;i++) {Lx[i]=w[i][1];  for(intj=2; j<=n;j++) Lx[i]=Max (lx[i],w[i][j]); }     for(intx=1; x<=n;x++) {memset (Slack,inf,sizeof(slack));  while(1) {memset (VISX,0,sizeof(VISX)); memset (Visy,0,sizeof(Visy)); if(Dfs (x)) Break; intD=inf;  for(intI=1; i<=n;i++)                if(!visy[i]&&d>Slack[i]) d=Slack[i];  for(intI=1; i<=n;i++)            {                if(Visx[i]) lx[i]-=D; if(Visy[i]) ly[i]+=D; Elseslack[i]-=D; }        }    }    intans=0;  for(intI=1; i<=n;i++)        if(link[i]>-1) ans+=W[link[i]][i]; returnans;}intMain () {//freopen ("In.txt", "R", stdin);     while(~SCANF ("%d",&N)) { for(intI=1; i<=n;i++)             for(intj=1; j<=n;j++) scanf ("%d",&W[i][j]); printf ("%d\n", km ()); }    return 0;}

HDU2255 Ben-off make money (km template problem)

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.