计算机学院大学生程序设计竞赛(2015’12)Happy Value
来源:互联网 发布:数据漫游是什么意思 编辑:程序博客网 时间:2024/05/25 18:10
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 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
20 11 030 1 51 0 35 3 0
Sample Output
18
#include <stdio.h>#include <string.h>#define MaxInt 9999999#define N 110int 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;}
1 0
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value(最大生成树)
- hdu 计算机学院大学生程序设计竞赛(2015’12)Happy Value(最大生成树)
- 计算机学院大学生程序设计竞赛(2015’12)1004 Happy Value
- 计算机学院大学生程序设计竞赛(2015’12)(STL )
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
- 计算机学院大学生程序设计竞赛(2015’12)Pick Game
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- hdu 计算机学院大学生程序设计竞赛(2015’11)质方数
- hdu 计算机学院大学生程序设计竞赛(2015’11)游乐场
- 计算机学院大学生程序设计竞赛(2015’11)
- hdu--计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- hdu-- 计算机学院大学生程序设计竞赛(2015’11)
- Java 集合框架(JCF)
- 15款android设备上的代码编辑器
- URLConnection的post请求网络数据和AsyncTask异步线程
- kafka 安装和测试
- 排序算法—堆排序算法分析与实现(Python)
- 计算机学院大学生程序设计竞赛(2015’12)Happy Value
- C函数指针
- 计算机学院大学生程序设计竞赛(2015’12)Bitwise Equations
- C/C++中整数与浮点数在内存中的表示方式
- BZOJ3295 CQOI2011 动态逆序对
- Android应用开发之自定义View触摸相关工具类全解
- 安卓eclipse 的ndk开发
- 计算机学院大学生程序设计竞赛(2015’12)01 Matrix
- Qt之文件操作