Happy Value
Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1337 accepted submission (s): 392
Problem Description in a apartment, there are N residents. The Internet Service Provider (ISP) wants to connect this residents with n–1 cables.
However, the friendships of the residents are different. There is a "Happy Value" indicating the degrees of a pair of residents. The higher "Happy Value" is, the friendlier a pair to residents is. So, the ISP wants to choose a connecting the "Happy Values" of the highest sum.
Input There are multiple test cases. Please process to end of file.
For each case, the the "the" number of the "the" contains only one integer N (2<=n<=100), indicating the number of the residents.
Then N lines follow. Each line contains N integers. Each integer H-ij (0<=h ij<=10000) in I th row and J th column indicates that I th resident have a "Happy Value" H ij with J Th resident. and H ij (i!=j) is equal to H ji. H IJ (i=j) is always 0.
Please output the answer at one line.
Sample Input
2 0 1 1, 0 3 0 1 5 1 0 3 5 3 0
Sample Output
1 8
always looking at once space in a daze, those who say not separate friends, turn around, strangers. Familiar, quiet, quiet, left, left, unfamiliar, unfamiliar, disappeared, disappeared, strangers.
#include <stdio.h> #include <string.h> #define MAXINT 9999999 #define N $ int Map[n][n],low[n],visited[n],n
;
int prim () {int i,j,pos=1,min,result=0;
memset (visited,0,sizeof (visited));
Visited[1]=1;
for (i=2; i<=n; i++) low[i]=map[pos][i];
for (I=1; i<n; i++) {min=maxint;
For (J=1 j<=n; j + +) if (Visited[j]==0&&min>low[j]) {min=low[j];
Pos=j;
} result+=min;
Visited[pos]=1;
For (J=1 j<=n; j + +) if (Visited[j]==0&&low[j]>map[pos][j]) low[j]=map[pos][j];
return result;
int main () {int i,v,j,ans;
while (scanf ("%d", &n)!=eof) {memset (map,maxint,sizeof (map));
For (I=1 i<=n; i++) for (j=1; j<=n; J + +) {scanf ("%d", &v);
Map[i][j]=-v;
} Ans=-1*prim (); printf ("%d\n", ans);
return 0;
}
@ hold read "@☆ but beg" ❤ "Ann ★ Next time we do will be better ....
for what
this time the topic is in English .... Qaq ...