计算机学院大学生程序设计竞赛(2015’12)Happy Value
Happy Value
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1337 Accepted Submission(s): 392
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”.
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.
2
0 1
1 0
3
0 1 5
1 0 3
5 3 0
1
8
总是望着曾经的空间发呆,那些说好不分开的朋友不在了,转身,陌路。 熟悉的,安静了, 安静的,离开了, 离开的,陌生了, 陌生的,消失了, 消失的,陌路了。
#include <stdio.h>
#include <string.h>
#define MaxInt 9999999
#define N 110
int 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;
}
@执念 "@☆但求“❤”安★
下次我们做的一定会更好。。。。
为什么这次的题目是英文的。。。。QAQ...
计算机学院大学生程序设计竞赛(2015’12)Happy Value的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 计算机学院大学生程序设计竞赛(2015’11)1005 ACM组队安排
1005 ACM组队安排 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Pro ...
- 计算机学院大学生程序设计竞赛(2015’12)Study Words
Study Words Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 计算机学院大学生程序设计竞赛(2015’12)Polygon
Polygon Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Su ...
- 计算机学院大学生程序设计竞赛(2015’12)The Country List
The Country List Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) ...
- 计算机学院大学生程序设计竞赛(2015’12) 1008 Study Words
#include<cstdio> #include<cstring> #include<map> #include<string> #include&l ...
- 计算机学院大学生程序设计竞赛(2015’12) 1009 The Magic Tower
#include<cmath> #include<cstdio> #include<cstring> #include<algorithm> using ...
- 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix
#include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...
- 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle
#include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...
- 计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value
#include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...
随机推荐
- J2ME开发入门
原文发布时间为:2008-07-31 -- 来源于本人的百度文章 [由搬家工具导入] J2ME开发入门J2ME方面开发的资料,确实是少之又少,一般给新手推荐的都是王森先生的《PDA与手机开发入门》一书 ...
- 标准C程序设计七---11
Linux应用 编程深入 语言编程 标准C程序设计七---经典C11程序设计 以下内容为阅读: <标准C程序设计>(第7版) 作者 ...
- cout与cerr
cout对应于标准输出流,默认情况下是显示器.这是一个被缓冲的输出,可以被重定向. cerr对应标准错误流,用于显示错误消息.默认情况下被关联到标准输出流,但它不被缓冲,也就说错误消息可以直接发送到显 ...
- 【westorm系列之二】配置格式化
1.执行格式化后,给句尾加分号
- 八皇后问题Python实现
八皇后问题描述 问题: 国际象棋棋盘是8 * 8的方格,每个方格里放一个棋子.皇后这种棋子可以攻击同一行或者同一列或者斜线(左上左下右上右下四个方向)上的棋子.在一个棋盘上如果要放八个皇后,使得她们互 ...
- 输出重定向、cat、系统别名、查看指定行、时间戳
1.touch命令:如果文件不存在则创建,如存在则更新时间戳;2.除了echo有向文件写入内容的功能,cat也可以; cat > hehe # 输出重定向 cat >> hehe # ...
- String的引用传递
一 引用传递的三个范例 范例一 package com.mtzsoft; /** * 范例一 * * @author Administrator * */ public class Test1 { p ...
- influxDB的安装和简单使用
单机的influxdb免费,集群的是收费的 1.安装,参考官方文档 https://portal.influxdata.com/downloads RedHat & CentOS: wget ...
- Android 集成支付宝支付详解
一说到支付宝,相信没有人不知道,生活中付款,转账都会用到. 今天来详细介绍下在Android中如何集成支付宝支付到自己的APP中去.让APP能够拥有方便,快捷的支付功能. 准备工作: 商户在b.ali ...
- JAVA_MyEclipse如何加载JDK JRE