#P4539. [SCOI2006] zh_tree
[SCOI2006] zh_tree
Description
Teacher Zhang designed a special binary search tree for his work.
He named this binary tree zh_tree. For a zh_tree with nodes, its inorder traversal is exactly , where the numbers are the identifiers of the nodes. The nodes correspond to distinct words that appear in a set of academic papers.
Let the -th word appear times; for example, means that the word corresponding to node appears times. Let be the total number of word occurrences in this set of papers. Obviously, . Define as the probability (frequency) of the -th word.
The root node has depth . If node has depth , then its access cost is , where and are known positive constants not exceeding .
A zh_tree is a binary tree that minimizes .
We call the expression above the average access cost of the zh_tree. Please design a zh_tree based on the given data.
Input Format
Line 1: Three positive numbers separated by spaces: , where is an integer. and are positive real numbers not exceeding .
Line 2: positive integers separated by spaces, the occurrence counts for each word (each count ).
Output Format
Output one positive real number on a single line, rounded to decimal places: the minimal average access cost of the zh_tree.
4 2 3.5
20 30 50 20
7.000
Hint
The original problem also required constructing the tree and outputting its inorder traversal. For various reasons, we removed that second requirement to keep compatibility with existing solutions and code.
Translated by ChatGPT 5
京公网安备 11011102002149号