#t414. 合并石子
合并石子
Stone Merging
Problem Description
On a playground, piles of stones are placed in a row. The stones must be merged into a single pile in the given order. In each move you may choose exactly two adjacent piles and merge them into a new pile; the score of that move is the total number of stones in the new pile.
Compute the minimum total score needed to merge the piles into one pile.
Input Format
The first line contains a positive integer ().
The next lines each contain a positive integer smaller than , giving the number of stones in the -th pile ().
Output Format
A single positive integer: the minimum score.
Sample Input
7
13
7
8
16
21
4
18
Sample Output
239
Limitation
1 s, 1024 KiB for each test case.