HDU 2255 (km algorithm template)

Source: Internet
Author: User

Ben Xiaokang makes a lot of money Time Limit: 1000/1000 MS (Java/others) memory limit: 32768/32768 K (Java/Others)
Total submission (s): 3707 accepted submission (s): 1618


Problem description it is said that there is a very rich village in a distant place. One day, the village chief decided to reform the system: re-allocate the house.
This is a major event that affects people's housing. There are a total of N rooms in the village, and there are just n common people. Considering that each room must have a house (if there are common people without a house, it is easy to cause instability ), each house must be allocated to one house and only one house can be obtained.
On the other hand, the village chief and other village leaders hope to get the greatest benefit, so that the village institutions will have money. because the common people are wealthy, they can make a certain price for each house in their economic scope. For example, if there are three houses, one common person can pay 0.1 million for the first house, 2nd for 20 thousand and 3rd for 0.2 million. (of course it is within their economic scope ). now the question is how village leaders can allocate houses to maximize revenue. (even if the villagers have money to buy a house, they may not be able to buy it. It depends on what the village leaders allocate ).

The input data contains multiple groups of test cases. The first line of each group of data is input N, indicating the number of houses (also the number of homes of ordinary people). Next there are n rows, the number of N entries in each row indicates the price (n <= 300) of the J room for the first village name ).

Output outputs the largest revenue value for each group of data, and each group of output occupies one row.


Sample Input
 
2100 1015 23

Sample output
123

Sourcehdoj 2008 Summer exercise (4)-buffet dinner AC code:
# Include <stdio. h >#include <string >#include <iostream> # include <algorithm> using namespace STD; int N; int W [305] [305]; int lx [305], ly [305], link [305]; int s [305], t [305]; int match (int I) {s [I] = 1; for (Int J = 1; j <= N; j ++) {If (LX [I] + ly [J] = W [I] [J] &! T [J]) {T [J] = 1; if (! Link [J] | match (link [J]) {link [J] = I; return 1 ;}} return 0 ;} void Update () {int A = 1 <20; For (INT I = 1; I <= N; I ++) {If (s [I]) {for (Int J = 1; j <= N; j ++) {If (! T [J]) {A = min (A, LX [I] + ly [J]-W [I] [J]) ;}}} for (INT I = 1; I <= N; I ++) {If (s [I]) lx [I]-= A; If (T [I]) ly [I] + = A ;}} int km () {for (INT I = 1; I <= N; I ++) {link [I] = Lx [I] = ly [I] = 0; For (Int J = 1; j <= N; j ++) {lx [I] = max (LX [I], W [I] [J]) ;}} for (INT I = 1; I <= N; I ++) {While (1) {for (Int J = 1; j <= N; j ++) s [J] = T [J] = 0; if (MATCH (I) break; else Update () ;}} int ret = 0; For (INT I = 1; I <= N; I ++) {If (link [I]) {RET + = W [LINK [I] [I];} return RET;} int main () {While (scanf ("% d", & N )! = EOF) {for (INT I = 1; I <= N; I ++) for (Int J = 1; j <= N; j ++) scanf ("% d", & W [I] [J]); int ans = km (); printf ("% d \ n", ANS );} return 0 ;}


HDU 2255 (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.