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. Ajax入门(一)从0开始到一次成功的GET请求

    什么是服务器 网页浏览过程分析 一个完整的HTTP请求过程,通常有下面7个步骤 建立TCP连接 Web浏览器向Web服务器发送请求命令 Web浏览器发送请求头信息 Web服务器- 应答 Web服务器- ...

  2. 杭电ACM刷题(1):1002,A + B Problem II 标签: acmc语言 2017-05-07 15:35 139人阅读 评

    最近忙于考试复习,没有多少可供自己安排的时间,所以我利用复习之余的空闲时间去刷刷杭电acm的题目,也当对自己编程能力的锻炼吧. Problem Description I have a very si ...

  3. SDUT 1177 C语言实验——时间间隔

    C语言实验——时间间隔 Time Limit: 1000MS Memory Limit: 65536KB Submit Statistic Discuss Problem Description 从键 ...

  4. 终极解决傻X阿里钱盾新手开店及老卖家复核身份证照片模糊无法对焦问题

    我小米3阿里钱盾认证拍照无法对焦,后来咨询客服,客服让买新的或借朋友的.然后百度了一下发现模糊现象不是个例,好多比较新的小米5,华为手机什么的也都模糊.真是幸庆,,差点就被客服带坑里去买新手机了. 然 ...

  5. SpringMVC 配置式开发-HandlerMapping的执行流程(八)

    具体看这两块是怎么执行的 下图是实现了DispatcherServlet从HandleMapping获得处理器执行链的逻辑的源代码 下面是DispatcherServlet从HandleAdaptor ...

  6. vimrc配置-中文编码和python中的中文注释

    set fileencoding=gb18030"设置vim输入的编码 set fileencodings=gb18030,...,"打开文档时vim自动匹配可能的编码方式 在py ...

  7. CSS预处理器(SASS和LESS)

    Sass框架应用Sass简介 Sass又名SCSS,是CSS预处理器之一,它能让你更好更轻松的工作.Sass官网是这样描述Sass的:**Sass是一门高于CSS的元语言,能用来清晰的.结构化地描述文 ...

  8. javascript window.showModalDialog不兼容goole解决方案

    window.showModalDialog不兼容goole解决方案 一.弹框方案: 1.window.open; 2.window.showModalDialog; 3.div制作窗口:(本节忽略) ...

  9. [Algorithm]树与二叉树

    一.树与二叉树相关算法 1.二叉树按顺序结构存储,求编号为i和j的两个结点的最近公共祖先结点的值 1 ElemType CommonAncestor( SeqTree T, int i, int j ...

  10. Binder学习笔记(七)—— ServiceManager如何响应addService请求

    有了<ServiceManager如何响应checkService请求>的探索,研究addService就轻车熟路了,中间过程不再多说,仅把关键节点列出: frameworks/nativ ...