博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 1789 Truck History 最小生成树 prim 难度:0
阅读量:4548 次
发布时间:2019-06-08

本文共 2865 字,大约阅读时间需要 9 分钟。

Truck History
Time Limit: 2000MS   Memory Limit: 65536K
Total Submissions: 19122   Accepted: 7366

Description

Advanced Cargo Movement, Ltd. uses trucks of different types. Some trucks are used for vegetable delivery, other for furniture, or for bricks. The company has its own code describing each type of a truck. The code is simply a string of exactly seven lowercase letters (each letter on each position has a very special meaning but that is unimportant for this task). At the beginning of company's history, just a single truck type was used but later other types were derived from it, then from the new types another types were derived, and so on. 
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 t
o is the original type and t
d the type derived from it and d(t
o,t
d) 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

The input consists of several test cases. Each test case begins with a line containing the number of truck types, N, 2 <= N <= 2 000. Each of the following N lines of input contains one truck type code (a string of seven lowercase letters). You may assume that the codes uniquely describe the trucks, i.e., no two of these N lines are the same. The input is terminated with zero at the place of number of truck types.

Output

For each test case, your program should output the text "The highest possible quality is 1/Q.", where 1/Q is the quality of the best derivation plan.

Sample Input

4aaaaaaabaaaaaaabaaaaaaabaaaa0

Sample Output

The highest possible quality is 1/3.

Source

 
#include 
#include
using namespace std;char str[2001][9];int d[2001][2001];int mind[2001];//mind restore the min distance of the point between the tree when the point hasn't been add into//rather than the point in the tree to all the point not in the treebool vis[2001];int n;int ans;int index;void setd(){ for(int i=0;i
>n&&n){ for(int i=0;i
>str[i]; } setd(); prim(); cout<<"The highest possible quality is 1/"<
<<".\n"; } return 0;}

  

转载于:https://www.cnblogs.com/xuesu/p/4093919.html

你可能感兴趣的文章
Dynamics CRM 给视图配置安全角色
查看>>
Eclipse修改已存在的SVN地址
查看>>
C++ ACM基础
查看>>
(转)使用 python Matplotlib 库绘图
查看>>
进程/线程切换原则
查看>>
正则表达式语法
查看>>
20165301 2017-2018-2 《Java程序设计》第四周学习总结
查看>>
Vue的简单入门
查看>>
使用最快的方法计算2的16次方是多少?
查看>>
urllib 中的异常处理
查看>>
【SQL Server高可用性】高可用性概述
查看>>
通过SQL Server的扩展事件来跟踪SQL语句在运行时,时间都消耗到哪儿了?
查看>>
SQL优化:重新编译存储过程和表
查看>>
PCB“有铅”工艺将何去何从?
查看>>
Solr环境搭建
查看>>
IE兼容性的一些。。
查看>>
第二章-递归与分治策略
查看>>
快速排查SQL服务器阻塞语句
查看>>
推荐系统常用数据集
查看>>
stack
查看>>