HDU计算机学院大学生程序设计竞赛(2015’12)Happy Value
Problem Description
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” Hij with jthresident. And Hij(i!=j) is equal to Hji. Hij(i=j) is always 0.
#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的更多相关文章
- hdu 计算机学院大学生程序设计竞赛(2015’11)
搬砖 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65535/65535 K (Java/Others)Total Submissi ...
- 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 ...
- HDU计算机学院大学生程序设计竞赛(2015’12)The Country List
Problem Description As the 2010 World Expo hosted by Shanghai is coming, CC is very honorable to be ...
- 计算机学院大学生程序设计竞赛(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 ...
随机推荐
- Android 图片相关
从asset文件夹中读取Bitmap //从asset文件夹中取文件 private Bitmap getImageFromAssetFile(String fileName){ Bitmap ima ...
- ListView里面adapter的不同分类的item
public class PlayAdapter extends BaseAdapter { /** * 标题的item */ public static final int ITEM_TITLE = ...
- 详解CSS float属性(转)
详解CSS float属性 阅读目录 基础知识 float的详细细节 float特殊情况 clear属性 清除浮动 float的应用 总结 CSS中的float属性是一个频繁用到的属性,对于初学者 ...
- AWT简介
-------------siwuxie095 AWT 简介: AWT(Abstract Window Toolkit)是最原始的 Java G ...
- schedule与scheduleAtFixedRate比较
schedule与scheduleAtFixedRate: 不延时: schedule(TimerTask, Date runDate, long period)方法任务不延时----Date类型 i ...
- 关于PDF的一些书籍
PDF Explained: The ISO Standard for Document Exchange https://ssearch.oreilly.com/?q=PDF+
- 添加超级链接为什么用a标签
a是anchor的简写,中文意思是锚点,而锚点的引申意思是连接,link已经被html占用了,只能用a来表示连接了.
- 算法Sedgewick第四版-第1章基础-016一list
import java.util.Iterator; import java.util.NoSuchElementException; public class List<Item> im ...
- c#中public,private,protected,internal的区别
public 可以被外部成员调用 private 只能在被类的成员调用 protected 只能在被类的成员和该类的子类调用 internal 可以在当前项目调用 pub ...
- Data Base mysql备份与恢复
mysql 备份与恢复 为什么要备份: 由于系统使用到了MySQL 数 据库,所以每天的工作,就设计到了MySQL数据库的备份问题.但如果每天手工来做MySQL数据库的定时备份,工作量不说,时间还不 ...