Ben-off make money HDU 2255

Source: Internet
Author: User

Ben-off make a lot of moneyTime limit:1000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 4211 Accepted Submission (s): 1825


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 Input
2100 1015 23

Sample Output
123

Sourcehdoj Summer Exercise (4)-Buffet Dinner
#include <iostream> #include <cstring> #include <cstdio>using namespace std;const int maxn = 310;const int inf = 1<<30;int WEIGHT[MAXN][MAXN]; Record the weights of all sides of the full dichotomy int match[maxn];//record the perfect match for the complete dichotomy bool VISX[MAXN], visy[maxn];//records whether the vertices in the X, Y collection appear in the augmented path int LX[MAXN], ly[ maxn];//records x, y each vertex's mark amount int slack[maxn];//record × on the augmentation path, y not on each side of the augmented path lx[x]+ly[y]-weight[x][y] to Y minimum value is placed in slack[y]//To enlarge equal Sub-graph (sub-graph of the dichotomy). BOOL Dfs (const int& x,const int& N) {visx[x] = 1;//x appears in the augmented path for (int i = 0; i < n; i + +) {if (vi        Sy[i]) continue;        int t = lx[x]+ly[i]-weight[x][i];            if (t = = 0) {//x on the augmented path, y on the augmented road visy[i] = 1;                if (match[i] = = 1 | | DFS (match[i], n)) {match[i] = x;            return true;        }} else {//x on the augmented path, y not on the augmented path slack[i] = min (slack[i], T); }}return false;}            int KM (const int& N) {memset (match,-1, sizeof (match));//Initialize, the maximum match for the binary graph is 0 for (int i = 0; i < n; i + +) { LX[i] = 0, ly[i] = 0; for (int j = 0; J < N; j + +) {Lx[i] = max (Lx[i], weight[i][j]);//Initialize LX as x's adjacent edge maximum weight, ly 0}} for (int i = 0; i < n; i + +)        {for (int j = 0; J < N; j + +) slack[j] = inf;            while (1) {memset (visx, 0, sizeof (VISX));//initialize x, y neither in the augmented path memset (visy, 0, sizeof (Visy)); if (Dfs (i, n)) break;            If the match succeeds, the maximum matching edge of the next X point is continued, the scalar of each point is failed to update, and the number of feasible edges is increased int d = INF;                for (int j = 0; J < N; j + +) {//Ask the starting point on the augmented path, while the end point is not the edge of the augmented path, the endpoint scalar and the minimum value of the Benquan difference.            if (!visy[j]) d = min (d, slack[j]);            } for (int j = 0; J < N; j + +) {if (Visx[j]) lx[j]-= D;                }//new scalar for (int j = 0; J < N; j + +) {if (Visy[j]) Ly[j] + + D;//More new scalar for y in Broad Road else Slack[j]-= D; Updates the minimum value of the slack.    (because the scalar of the augmented path x that is connected to J in Y is reduced by D)}}} int res = 0;       for (int i = 0; i < n; i + +) {//y may have no matching points in the collection if (Match[i] >-1) Res + = Weight[match[i]][i]; }return Res;}   int main () {int n;            while (scanf ("%d", &n)!=eof) {for (int i = 0; i < n; i + +) {for (int j = 0; J < N; j + +) {        scanf ("%d", &weight[i][j]);      }} int ans = KM (n);   printf ("%d\n", ans); }return 0;}


Ben-off make money HDU 2255

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.