ACM: 图论题 poj 1789 (一次AC的水…
来源:互联网 发布:淘宝网店加盟哪家好 编辑:程序博客网 时间:2024/05/18 23:53
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 ofa truck. The code is simply a string of exactly seven lowercaseletters (each letter on each position has a very special meaningbut that is unimportant for this task). At the beginning ofcompany's history, just a single truck type was used but laterother types were derived from it, then from the new types anothertypes 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 distanceof truck types as the number of positions with different letters intruck type codes. They also assumed that each truck type wasderived from exactly one other truck type (except for the firsttruck type which was not derived from any other type). The qualityof a derivation plan was then defined as
where the sum goes over all pairs of types in the derivation plansuch that to is the original type and td thetype derived from it and d(to,td) is thedistance 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 thehighest possible quality of a derivation plan.
Input
The input consists of several test cases. Each test case beginswith a line containing the number of truck types, N, 2<= N <= 2 000. Each of the followingN lines of input contains one truck type code (a string of sevenlowercase letters). You may assume that the codes uniquely describethe trucks, i.e., no two of these N lines are the same. The inputis terminated with zero at the place of number of truck types.
Output
For each test case, your program should output the text "Thehighest possible quality is 1/Q.", where 1/Q is the quality of thebest derivation plan.
Sample Input
4
aaaaaaa
baaaaaa
abaaaaa
aabaaaa
0
Sample Output
The highest possible quality is 1/3.
题意:
解题思路:
代码:
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
const int INF = (1<<20);
#define MAX 2005
int dist[MAX];
bool vis[MAX];
int n;
char str[MAX][10];
int distance(char* a,char* b)
{
}
void read_graph()
{
}
int prim()
{