标签:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 1453 Accepted Submission(s): 428
#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
标签:
原文地址:http://www.cnblogs.com/yinghualuowu/p/5087151.html