Ben-off make a lot of money

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): 5598 Accepted Submission (s): 2457

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 1015 Output123 sourcehdoj Summer Exercise (4)-Buffet Dinner test instructions: Each house has a cost per room, how to allocate can make the total cost maximum 。 KM
1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 6 using namespacestd;7 8 #defineN 3309 #defineINF 0XFFFFFFFTen  One intN, S[n]; A intLx[n], ly[n], maps[n][n], used[n], visx[n], visy[n]; -  - intFoundintu) the { -Visx[u] =true; -      for(inti =1; I <= N; i++) -     { +         if(!visy[i] && Lx[u] + ly[i] = =Maps[u][i]) -         { +Visy[i] =1; A             if(!used[i] | |found (Used[i])) at             { -Used[i] =u; -                 return true; -             } -         } -         Else inS[i] = min (s[i], lx[u]+ly[i]-maps[u][i]); -     } to     return false; + } -  the intKM () * { $memset (Used,0,sizeof(used));Panax Notoginsengmemset (LX,0,sizeof(LX)); -memset (Ly,0,sizeof(ly)); the  +      for(inti =1; I <= N; i++) A          for(intj =1; J <= N; J + +) theLx[i] =Max (Lx[i], maps[i][j]); Each LX saved is the maximum value that can be, ly is 0, and the sum is the maximum amount of money that you have invested.  +      for(inti =1; I <= N; i++) -     { $          for(intj =1; J <= N; J + +) $S[J] =INF; -          while(1) -         { thememset (VISX,0,sizeof(VISX)); -memset (Visy,0,sizeof(Visy));Wuyi  the             if(found (i)) -                  Break; Wu             intD =INF; -              for(intj =1; J <= N; J + +) About                 if(!Visy[j]) $D =min (d, s[j]); If the maximum value match is not found, the minimum value needs to be reduced so that the matching minus minimum value can be completed with the maximum match -              for(intj =1; J <= N; J + +) -             { -                 if(Visx[j]) ALX[J]-=D; +                 if(Visy[j]) theLY[J] + =D; -             } $         } the     } the     intAns =0; the      for(inti =1; I <= N; i++) theAns + =Maps[used[i]][i]; -     returnans; in } the  the intMain () About { the      while(~SCANF ("%d", &N)) the     { the          for(inti =1; I <= N; i++) +         { -              for(intj =1; J <= N; J + +) the             {Bayiscanf"%d", &maps[i][j]); the             } the         } -printf"%d\n", KM ()); -     } the     return 0; the}

Ben-off make a lot of money

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.