HDU Computer College College Student Program Design Contest (Happy) Value

Source: Internet
Author: User

Happy Value

Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1453 Accepted Submission (s): 428

Problem DescriptionIn an apartment, there is N residents. The Internet Service Provider (ISP) wants to connect these residents with n–1 cables.
However, the friendships of the residents is different. There is a "Happy Value" indicating the degrees of a pair of residents. The higher "Happy Value" is, the friendlier a pair of residents are. So the ISP wants to choose a connecting plan to make the highest sum of "Happy Values". Inputthere is multiple test cases. Please process to end of file.
The first line contains only one integer N (2<=n<=100), indicating the number of the residents.
Then N lines follow. Each line contains N integers. Each of the integer Hij (0<=hij<=10000) in the ith row and jth column indicates that ITH resident has a "Happy Value" Hij with Jthresident. and Hij (i!=j) is equal to Hji. Hij (I=J) is always 0.OutputFor each case, please output the answer on one line. Sample Input20 030 1 0 3 0Sample Output18 maximum spanning tree The algorithm of the bottom spanning tree is inverted. For example, change the weight to a negative number, and return the result.
#include <stdio.h>//#include <bits/stdc++.h> #include <string.h> #include <iostream> #include <math.h> #include <sstream> #include <set> #include <queue>//#include <map> #include < vector> #include <algorithm> #include <limits.h> #define INF 0x3fffffff#define inf 0x3f3f3f3f#define Lson L,m,rt<<1#define Rson m+1,r,rt<<1|1#define LL long long#define ULL unsigned long longusing namespace Std;int m    Ap[110][110];int dis[110];int flag[110];int n;int Prime () {int i,j;    int pos,sum=0;    memset (flag,0,sizeof (flag));    for (I=1; i<=n; i++) {dis[i]=map[1][i];    } flag[1]=1;        for (I=1; i<n; i++) {int mid=inf;                for (j=1; j<=n; J + +) {if (!flag[j]&&dis[j]<mid) {mid=dis[j];            Pos=j;        }} flag[pos]=1;        Sum+=mid; for (j=1; j<=n; J + +) {if (!flag[j]&&map[pos][j]<dis[j]) {dis[j]=map[pos][j]; }}} return sum;}    int main () {int i,j;    int q,a,b;        while (~SCANF ("%d", &n)) {memset (map,0,sizeof (map));        int ans;                for (I=1; i<=n; i++) {for (j=1; j<=n; J + +) {scanf ("%d", &ans);            Map[i][j]=-ans;    }} printf ("%d\n",-prime ()); } return 0;}

  

HDU Computer College College Student Program Design Contest (Happy) Value

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.