Happy Value
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1350 Accepted Submission(s): 400
Problem Description
In an apartment, there are N residents. The Internet Service Provider (ISP) wants to connect these 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 of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
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 of residents is. So the ISP wants to choose a connecting plan to make the highest sum of “Happy Values”.
Input
There are multiple test cases. Please process to end of file.
For each case, 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 integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hijwith jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
For each case, 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 integer Hij(0<=Hij<=10000) in ith row and jth column indicates that ith resident have a “Happy Value” Hijwith jth resident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
Output
For each case, please output the answer in one line.
Sample Input
2 0 1 1 0 3 0 1 5 1 0 3 5 3 0
Sample Output
1 8#include <iostream> #include <cstring> #include <cstdio> #include <cstdlib> #include <cmath> #include <algorithm> #include <queue> #include <stack> #include <set> #include <map> #include <list> #define LL long long #define INF 0x3f3f3f3f using namespace std; int h[110][110]; int eveco[110]; bool vis[110]; int Pri(int n) { memset(vis,false,sizeof(vis)); for(int i=1;i<=n;i++) eveco[i] = h[1][i]; int cost = 0; vis[1] = true; eveco[1] = 0; for(int i=1;i<n;i++) { int m = 0,pos; for(int j=1;j<=n;j++) { if(m < eveco[j] && !vis[j]) pos = j, m= eveco[j]; } cost += m; vis[pos] = true; for(int j=1;j<=n;j++) if(!vis[j] && eveco[j] < h[pos][j]) eveco[j] = h[pos][j]; } return cost; } int main() { int n; while(cin>>n) { for(int i=1; i<=n; i++) { for(int j=1; j<=n; j++) { cin>>h[i][j]; } } cout<<Pri(n)<<endl; } return 0; }
最高快乐值连接方案

本文介绍了一种寻找最佳连接方案的问题,旨在通过构建最优的居民间互联网连接来最大化总快乐值。该方案需要考虑每对居民间的友好度,并选择合适的连接路径以确保最高的累积快乐值。
3611

被折叠的 条评论
为什么被折叠?



