codevs1090 plus two forks of trees2003 NOIP National League Improvement Group title description
Description
The mid-order traversal of a two-ary tree with an n node is (l,2,3,..., N), where the number,..., n is a node number. Each node has a fraction (all positive integers), the score for the J node is di,tree and each of its subtrees has an extra point, and any subtrees tree subtree (also including the tree itself) is calculated as follows:
Subtree The xsubtree of the right subtree of the left sub-tree and the score of the root of the +subtree.
If a subtree is dominated, it is specified to be divided into 1, and the addition of leaves is the fraction of the leaf node itself. Without regard to its emptiness
Subtree
Try to find a tree of two trees that matches the middle order traversal (,..., N) and has the highest added score. Required output;
(1) Maximum bonus points for tree
Now, please help your good friend XZ design a program to get the right answer.
Enter a description
Input Description
Line 1th: An integer n (n<=30), which is the number of nodes.
Line 2nd: n spaces separated by integers, for each node's score (fractional <=100)
Output description
Output Description
Line 1th: An integer that is the highest plus score (the result will not exceed 4,000,000,000).
Sample input
Sample Input
5
5 7 1) 2 10
Sample output
Sample Output
145
Data range and Tips
Data Size & Hint
N (n<=30)
Score <=100
Exercises
First of all, most of the problems in the middle sequence traversal have a feature is to enumerate the root node, in the middle sequence in the root node in front of the left subtree, followed by the right sub-tree
The maximum score of a two-fork tree with this root node in a tree-shaped dp,dp[i]=
Dp[i]=max (dp[left dial hand tree],dp[right subtree])
First enumerate the root node and recursively do the left and right subtree
Finally Max (Dp[i]) is the positive solution
CODEVS1090 plus two forks of trees