HBC237189递归次数Spring Tree题解

八贝勒 算法基础篇 46 0
想要成为编程高手?那就来试试全网最全C++题库,让您在练习中快速成长。
n1 springs to connect them into a tree.1 is the root of the tree. Now we grasp the root and hang the whole tree.At this time, PaiGuDragon come up with an evil idea. It plans to rearrange the. w sequence, that is, PaiGuDragon is going to generate an array. Considering all the arrangements, what is the maximum of maximum depth of the tree after hanging?Here, the maximum depth is defined as the maximum value of the sum of the spring lengths on the path from the leaf to the root.

There are n n iron balls numbered 1 1 to n n, and the weight of the i i th ball is w_i w i ​ . We use n - 1 n−1 springs to connect them into a tree. The ball numbered 1 1 is the root of the tree. Now we grasp the root and hang the whole tree. The initial length of each spring is 1 1. If the weight of the subtree it hangs is g g, its length will become 1 + g 1+g. At this time, PaiGuDragon come up with an evil idea. It plans to rearrange the w w sequence, that is, PaiGuDragon is going to generate an array p_1,p_2,...,p_n p 1 ​ ,p 2 ​ ,...,p n ​ which is a permutation of 1,2....,n 1,2....,n, and then the weight of the i i th ball will become w_{p_i} w p i ​ ​ Considering all the arrangements, what is the maximum of maximum depth of the tree after hanging? Here, the maximum depth is defined as the maximum value of the sum of the spring lengths on the path from the leaf to the root.

HBC237189递归次数Spring Tree题解
-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC237189递归次数Spring Tree题解