poj1789 最小生成树
题目连接:http://poj.org/problem?id=1789
Description
Today, ACM is rich enough to pay historians to study its history. One thing historians tried to find out is so called derivation plan -- i.e. how the truck types were derived. They defined the distance of truck types as the number of positions with different letters in truck type codes. They also assumed that each truck type was derived from exactly one other truck type (except for the first truck type which was not derived from any other type). The quality of a derivation plan was then defined as
1/Σ(to,td)d(to,td)
where the sum goes over all pairs of types in the derivation plan such that to is the original type and td the type derived from it and d(to,td) is the distance of the types.
Since historians failed, you are to write a program to help them. Given the codes of truck types, your program should find the highest possible quality of a derivation plan.
Input
Output
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#define MAX 2005
#define INF 14005
using namespace std;
int G[MAX][MAX];
int d[MAX];
};
char a[MAX][MAX];
int n;
int prim(int s)
{
vis[s]=;
;i<n;i++)
d[i]=G[s][i];
int now,m;
;
;i<n;i++)
{
m=INF;
;j<n;j++)
{
if(!vis[j]&&d[j]<m)
{
now=j;
m=d[j];
}
}
vis[now]=;
res+=m;
;j<n;j++)
{
if(!vis[j]&&d[j]>G[now][j])
d[j]=G[now][j];
}
}
return res;
}
void init()
{
memset(vis,,sizeof(vis));
;i<n;i++)
;j<n;j++)
G[i][j]=INF;
}
int getdis(char * a,char * b)
{
;
;i<;i++)
{
if(a[i]!=b[i])
res++;
}
return res;
}
int main()
{
while(scanf("%d",&n)!=EOF)
{
)
;
init();
;i<n;i++)
scanf("%s",a[i]);
;i<n;i++)
;j<n;j++)
G[i][j]=getdis(a[i],a[j]);
printf());
}
}
poj1789 最小生成树的更多相关文章
- 28-Truck History(poj1789最小生成树)
http://poj.org/problem?id=1789 Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submiss ...
- 最小生成树Prim poj1258 poj2485 poj1789
poj:1258 Agri-Net Time Limit: 1000 MS Memory Limit: 10000 KB 64-bit integer IO format: %I64d , %I64u ...
- POJ1789&ZOJ2158--Truck History【最小生成树变形】
链接:http://poj.org/problem?id=1789 题意:卡车公司有悠久的历史,它的每一种卡车都有一个唯一的字符串来表示,长度为7,它的全部卡车(除了第一辆)都是由曾经的卡车派生出来的 ...
- POJ1789 Truck History 【最小生成树Prim】
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 18981 Accepted: 7321 De ...
- poj1789 Truck History最小生成树
Truck History Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20768 Accepted: 8045 De ...
- 最小生成树练习3(普里姆算法Prim)
风萧萧兮易水寒,壮士要去敲代码.本女子开学后再敲了.. poj1258 Agri-Net(最小生成树)水题. #include<cstdio> #include<cstring> ...
- POJ-1789 Truck History---最小生成树Prim算法
题目链接: https://vjudge.net/problem/POJ-1789 题目大意: 用一个7位的string代表一个编号,两个编号之间的distance代表这两个编号之间不同字母的个数.一 ...
- kuangbin最小生成树专题
网址:https://vjudge.net/contest/66965#overview 第一题: poj1251 裸最小生成树 #include<iostream> #include&l ...
- 最小生成树(Kruskal算法-边集数组)
以此图为例: package com.datastruct; import java.util.Scanner; public class TestKruskal { private static c ...
随机推荐
- SqlServer中临时表的应用
一.变通处理WHERE后面IN的参数过多 WHERE后面的条IN操作符里的参数比较小时,可以直接使用IN(1,2,3)这样处理,当个数不确定(可能超过1000)时,应该考虑使用临时表关联查询: SEL ...
- Website Collection
前一百个卡特兰数 Candy?的博弈论总结 杜教筛资料 线性基资料 (ex)BSGS资料 斐波那契数列前300项 斯特林数 STL标准库-容器-unordered_set C++ unordered_ ...
- 假的kd-tree小结
至今还不是很体会kd-tree这种东西,只不过体会了一种解决某些枚举问题的方法,就是当我们有一群元素,我们要到一个答案,答案在这些元素中的某个或某几个中,我们就会枚举他们,然而我们发现这样做十分低效, ...
- [8.16模拟赛] 玩具 (dp/字符串)
题目描述 儿时的玩具总是使我们留恋,当小皮还是个孩子的时候,对玩具更是情有独钟.小皮是一个兴趣爱好相当广泛且不专一的人,这这让老皮非常地烦恼.也就是说,小皮在不同时刻所想玩的玩具总是会不同,而有心的老 ...
- function(data)
转:http://blog.csdn.net/lixld/article/details/12206367 之前用了$.post()已经很久了,可是从来没有好好研究过这里的data对象,今天好好总结下 ...
- 在Global.asax中过滤POST请求的非法参数。
using System;using System.Collections.Generic;using System.Collections.Specialized;using System.Linq ...
- linux查看操作系统是多少位
有三种方法: 1.echo $HOSTTYPE 2.getconf LONG_BIT,此处不应该是getconf WORD_BIT命令,在64位系统中显示的是32 3.uname -a 出现" ...
- javascript中的递增递减操作符
javascript中递增递减属于一元操作符,所谓一元操作符,即只能操作一个值的操作符. 递增和递减操作符各有两个版本:前置型和后置型.顾名思义,前置型应该位于要操作的变量之前,而后置型应该位于要操作 ...
- 转载--博弈问题及SG函数(真的很经典)
博弈问题若你想仔细学习博弈论,我强烈推荐加利福尼亚大学的Thomas S. Ferguson教授精心撰写并免费提供的这份教材,它使我受益太多.(如果你的英文水平不足以阅读它,我只能说,恐怕你还没到需要 ...
- 【HDU】6146 Pokémon GO
[题意]一个2*n的网格,再保证步数最少的情况下,求从任意格出发遍历完所有格的方案数,格子八连通.n<=10000,T<=100. [算法]递推,DP [题解]原题链接:蓝桥杯 格子刷油漆 ...