#P1775. 石子合并(弱化版)
石子合并(弱化版)
Description
There are piles of stones in a row, numbered . Each pile has a mass . The goal is to merge these piles into one pile. Each time, you may only merge two adjacent piles, and the cost of merging is the sum of the masses of these two piles. After merging, the piles that were adjacent to the two merged piles become adjacent to the new pile. Because different merging orders lead to different total costs, find a method that minimizes the total cost, and output the minimum cost.
Input Format
The first line contains an integer . The second line contains integers .
Output Format
Output a single integer, the minimum cost.
4
2 5 3 1
22
Hint
Translated by ChatGPT 5
京公网安备 11011102002149号