題目來源:http://acm.pku.edu.cn/JudgeOnline/problem?id=1789
解題報告:
還是典型的最小生成樹的問題,我用了Kruskal算法,discuss裏說,Prim算法適合稠密圖,Kruskal算法適合稀疏圖。這道題顯然是稠密圖,所以應該用Prim算法比較合適,不過我還是不太會用prioriy_queue,只能用Kruskal算法。。。
附錄:
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 7498 | Accepted: 2664 |
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
Sample Input
4 aaaaaaa baaaaaa abaaaaa aabaaaa 0
Sample Output
The highest possible quality is 1/3.