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”.
 
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.
 
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 <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的更多相关文章

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

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

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

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

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

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

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

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

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

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

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

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

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

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

  8. 计算机学院大学生程序设计竞赛(2015’12) 1006 01 Matrix

    #include<stdio.h> #include<string.h> #include<iostream> #include<algorithm> ...

  9. 计算机学院大学生程序设计竞赛(2015’12) 1003 The collector’s puzzle

    #include<cstdio> #include<algorithm> using namespace std; using namespace std; +; int a[ ...

  10. 计算机学院大学生程序设计竞赛(2015’12) 1004 Happy Value

    #include<cstdio> #include<cstring> #include<cmath> #include<vector> #include ...

随机推荐

  1. Pizza Delivery

    Pizza Delivery 时间限制: 2 Sec  内存限制: 128 MB 题目描述 Alyssa is a college student, living in New Tsukuba Cit ...

  2. 【BZOJ2002】弹飞绵羊(LCT)

    题意:给定一棵树,要求维护以下操作: 1.删除连接(x,y)的边 2.将(x,y)之间连边 3.询问某点子树大小 对于100%的数据n<=200000,m<=100000 思路:第一道有加 ...

  3. BZOJ——1571: [Usaco2009 Open]滑雪课Ski

    http://www.lydsy.com/JudgeOnline/problem.php?id=1571 Time Limit: 10 Sec  Memory Limit: 64 MBSubmit:  ...

  4. BZOJ——1614: [Usaco2007 Jan]Telephone Lines架设电话线

    Time Limit: 5 Sec  Memory Limit: 64 MBSubmit: 1930  Solved: 823[Submit][Status][Discuss] Description ...

  5. Log4J使用详情

    一 .Log4J使用详情 Log4J的配置文件(Configuration File)就是用来设置记录器的级别.存放器和布局的,它可接key=value格式的设置或xml格式的设置信息.通过配置,可以 ...

  6. Hadoop 连接mysql

    1 mysql数据导入到hdfs数据 hadoop提供了org.apache.hadoop.io.Writable接口来实现简单的高效的可序列化的协议,该类基于DataInput和DataOutput ...

  7. __new__ 和 __init__

    new 在新式类中负责真正的实例化对象,而__init__只是负责初始化 __new__创建的对象.一般来说 new 创建一个内存对象,也就是实例化的对象的实体,交给__init__进行进一步加工.官 ...

  8. Android Studio如何Format代码

    Android Studio如何Format代码 Reformat code Shift + CTRL + ALT + L (Win) OPTION + CMD + L (Mac)

  9. 构建可读性更高的 ASP.NET Core 路由

    原文:构建可读性更高的 ASP.NET Core 路由 一.前言 不知你在平时上网时有没有注意到,绝大多数网站的 URL 地址都是小写的英文字母,而我们使用 .NET/.NET Core MVC 开发 ...

  10. Python机器学习-分类

    监督学习下的分类模型,主要运用sklearn实践 kNN分类器 决策树 朴素贝叶斯 实战一:预测股市涨跌 # -*- coding: utf-8 -*- """ Crea ...