#P9483. [NOI2023] 合并书本
[NOI2023] 合并书本
Problem Description
Xiao C has books, each with a weight. He decides to merge them into one pile.
In each merge, Xiao C can put one pile of books on top of another pile, so that they become one pile. If Xiao C puts the -th pile onto the -th pile, the stamina cost is the weight of the -th pile plus the sum of the wear values of the two piles.
Initially, each book forms its own pile and all wear values are . Each time Xiao C merges two piles, the new pile’s wear value becomes twice the larger wear value of the two piles plus one, and its weight becomes the sum of the weights of the two piles.
Your task is to design the merging order to minimize Xiao C’s stamina cost, and output this minimum cost.
Input Format
This problem has multiple test cases.
The first line contains a positive integer , the number of test cases.
Then for each test case:
The first line contains a positive integer , meaning there are books.
The second line contains positive integers; the -th number is the weight of the -th book.
Output Format
For each test case, output one integer per line, representing the minimum stamina required to merge the books into one pile.
1
4
1 1 1 1
6
见附件中的 book/book2.in。
见附件中的 book/book2.ans。
见附件中的 book/book3.in。
见附件中的 book/book3.ans。
见附件中的 book/book4.in。
见附件中的 book/book4.ans。
Hint
[Sample Explanation #1]
If Xiao C first merges the books in pairs, and then merges the two resulting piles into one pile, then the stamina costs of the first two merges are both . For the third merge, he puts a pile of weight onto the other pile; both piles have wear value , so the stamina cost is .
Therefore, under this plan, Xiao C’s total stamina cost is only .
It can be proven that, in the above example, is the minimum stamina cost.
[Constraints]
For all test cases: , , .
| Test Point ID | Special Property | |
|---|---|---|
| No | ||
| Yes | ||
| No |
Special property: it is guaranteed that .
Translated by ChatGPT 5