CODEVS1090 plus two forks of trees

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.