#P1880. [NOI1995] 石子合并
[NOI1995] 石子合并
Description
Along the circumference of a circular track, there are piles of stones. We want to merge the stones into one pile in some order. Each time, we can only choose two adjacent piles and merge them into a new pile; the number of stones in the new pile is recorded as the score for that merge.
Design an algorithm to compute the minimal total score and the maximal total score for merging piles into pile.
Input Format
The first line contains the positive integer , the number of piles.
The second line contains integers; the -th integer denotes the number of stones in the -th pile.
Output Format
Output a total of lines. The first line is the minimal total score, and the second line is the maximal total score.
4
4 5 9 4
43
54
Hint
Constraints: , .
Translated by ChatGPT 5
京公网安备 11011102002149号