poj 1258
来源:互联网 发布:暗黑2优化的高清补丁 编辑:程序博客网 时间:2024/05/21 10:59
简单题,直接用prim算法就可以啦.
#include <iostream>#include <cstdio>#include <cstring>const int maxn = 110;using namespace std;int map[maxn][maxn];bool flag[maxn];int Prim(int n){ int t = n; int k,ans = 0; while(--t){ int MIN = 1000000; for(int i = 2; i <= n; ++i) if(!flag[i] && MIN > map[1][i]){ MIN = map[1][i]; k = i; } flag[k] = true; ans += MIN; for(int i = 2; i <= n; ++i) if(!flag[i] && map[k][i] < map[1][i]) map[1][i] = map[k][i]; } return ans;}int main(){ int n; while(~scanf("%d",&n)){ memset(flag,false,sizeof(flag)); for(int i = 1; i <= n; ++i) for(int j = 1; j <= n; ++j) scanf("%d",&map[i][j]); printf("%d\n",Prim(n)); } return 0;}
- Poj 1258
- poj 1258
- POJ 1258
- poj 1258
- POJ 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- poj 1258
- poj 1258
- poj 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ 1258
- POJ - 1258
- 多校联合第8场1003Mine
- freemarker使用中,如何解决ftl页面自动去除属性值中间空格
- MAC电脑如何安装双系统-----文字阐述篇
- android 4高级编程(第三版)
- java InputStream读取数据问题
- poj 1258
- 关于dns使用协议的探究
- 提取用','分割的单词
- 证明spring mvc的Controller声明实例变量出问题
- Ajax响应中文乱码 [SpringMVC使用@ResponseBody处理Ajax请求]
- java应用
- hdu 1207 汉诺塔II
- 分层架构下的纯JDBC事务控制简单解决方案
- 关于丢番图方程x^2-dy^2=-1