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”.
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” Hij with jthresident. 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<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 long
using namespace std;
int map[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计算机学院大学生程序设计竞赛(2015’12)Happy Value的更多相关文章

  1. hdu 计算机学院大学生程序设计竞赛(2015’11)

    搬砖 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...

  2. HDU计算机学院大学生程序设计竞赛(2015’12)The Magic Tower

    Problem Description Like most of the RPG (role play game), “The Magic Tower” is a game about how a w ...

  3. HDU计算机学院大学生程序设计竞赛(2015’12)The Country List

    Problem Description As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable to be ...

  4. 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排

    1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Pro ...

  5. 计算机学院大学生程序设计竞赛(2015’12)Study Words

    Study Words Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Tota ...

  6. 计算机学院大学生程序设计竞赛(2015’12)Polygon

    Polygon Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Su ...

  7. 计算机学院大学生程序设计竞赛(2015’12)The Country List

    The Country List Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) ...

  8. 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words

    #include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...

  9. 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower

    #include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...

随机推荐

  1. js利用数组实现队列与堆栈效果

    之前在写Android的时候,会用到很多的队列与堆栈方式,其实js利用数组可以简单的实现类似的效果. 队列实现 var queue = new Array(); // unshift() 方法可向数组 ...

  2. C++面向对象类的实例题目九

    题目描述: 编写一个学生和老师数据输入和显示程序,学生数据有编号.姓名.班号和成绩,教师数据有编号.姓名.职称和部门. 要求将编号.姓名.输入和显示设计成一个类person,并作为学生数据操作类stu ...

  3. Navicat MySQL安装

    1 下载安装包 点击下载安装包 2 解压安装包(解压后有三个文件) 第一个 Crack 是注册文件 第二个 chinese.rar 是汉化包 第三个 navicat_trial.exe 是安装程序 3 ...

  4. 前端基础 之 BOM和DOM

    浏览目录 背景 BOM window对象 window的子对象 DOM HTML DOM树 查找标签 节点操作 事件 一.背景 到目前为止,我们已经学过了JavaScript的一些简单的语法.但是这些 ...

  5. JQuery UI Draggable插件使用说明文档

    JQuery UI Draggable插件用来使选中的元素可以通过鼠标拖动.Draggable的元素受css: ui-draggable影响, 拖动过程中的css: ui-draggable-drag ...

  6. GridView内按钮Click获取记录主键值 在GridView控件中,每行记录内会放置一个铵钮,当用

    在GridView控件中,每行记录内会放置一个铵钮,当用户点击这个铵钮时,获取当笔记录的主键值.可看演示(是一个gif动画,重新播放尝试刷新网页): 实现这个功能,你需要为GridView控件设置Da ...

  7. 事件Event 介绍总结

    最近在总结一些基础的东西,主要是学起来很难懂,但是在日常又有可能会经常用到的东西.前面介绍了 C# 的 AutoResetEvent的使用介绍, 这次介绍事件(event). 事件(event),对于 ...

  8. Web Api 测试工具

    1.调用POST方法:使用Chrome流量器的PostMan工具. 前端模拟发送数据/调试的好工具:Chrome下的Postman-REST Client 下载地址 https://chrome.go ...

  9. Kotlin 数据类型(数值类型)

    Kotlin 的常见数据类型: 类型 范围 byte -128~127 short 32767-32768 int -2147483648~2147483647 long 92233720368547 ...

  10. UIPageViewController

    前言 iPhone 和 iPad 都是通过页控件来展示多个桌面,很多 App 在第一次使用时也会使用页控件来介绍自己的功能,页控件的交互效果非常好,适用于把几个简单的页面充分展示出来. 1.UIPag ...