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. DevTools in Spring Boot 1.3

    Spring Boot 1.3 will ship with a brand new module called spring-boot-devtools. The aim of this modul ...

  2. 【276】◀▶ Python 字符串函数说明

    参考:Python 字符串函数 01   capitalize 把字符串的第一个字符大写,其他字母变小写. 02   center 返回一个原字符串居中,并使用空格填充至长度 width 的新字符串. ...

  3. c++primer-p100.用迭代器进行二分法搜索

    #include <vector> #include <iostream> using namespace std; int main() { vector<int> ...

  4. python爬虫(1)--Urllib库的基本使用

    这里使用python2.7,pycharm进行代码编写 1.爬一个静态网页示例 import urllib2 response = urllib2.urlopen("http://www.b ...

  5. 装饰器,装饰器多参数的使用(*arg, **kwargs),装饰器的调用顺序

    一.#1.执行outer函数,并且将其下面的函数名,当作参数 #2.将outer的返回值重新赋值给f1 = outer的返回值 #3.新f1 = inner #4.func = 原f1 #!/usr/ ...

  6. C++结构体的定义、初始化和引用

    定义: 结构体(struct)是由一系列具有相同类型或不同类型的数据构成的数据集合,也叫结构. 声明一个结构体类型的形式是: struct Student{ //声明一个结构体类型Student in ...

  7. 【摘自张宴的"实战:Nginx"】try_files指令

    语法:try_files param1 [param2...paramN] fallback 默认值:none 使用环境: location 该指令用于告诉nginx测试每个文件是否存在,并且使用首先 ...

  8. JavaWeb面试题 有用

    ajax的原理简单来说通过XmlHttpRequest对象来向服务器发异步请求,从服务器获取数据,然后用JavaScript来操作DOM从而更新页面的局部显示. Ajax的优点: 1.最大的一点是页面 ...

  9. 前端(HTML/CSS/JS)-CSS编码规范

    1. 文件名规范 文件名建议用小写字母加中横线的方式.为什么呢?因为这样可读性比较强,看起来比较清爽 https://stackoverflow.com/questions/25704650/disa ...

  10. C++文件流打开标识符.RP

    ofstream流,以ios::app打开(或者“ios::app|ios::out”),如果没有文件,那么生成空文件:如果有文件,那么在文件尾追加.以ios::app|ios::in打开,不管有没有 ...