#P5569. [SDOI2008] 石子合并

    ID: 6322 远端评测题 1000ms 125MiB 尝试: 0 已通过: 0 显示难度省选/NOI− 上传者: 标签>贪心2008各省省选山东

[SDOI2008] 石子合并

Problem Description

On a playground, there is a row of NN piles of stones. Now you need to merge the piles in order into a single pile. Each time, you may only choose two adjacent piles to merge into a new pile, and the number of stones in the new pile is counted as the score of this merge.

Design an algorithm to compute the minimum total score needed to merge the NN piles into one pile.

Input Format

The first line contains an integer NN.

In the next NN lines, the ii-th line contains an integer aia_i, representing the number of stones in the ii-th pile.

Output Format

Output the minimum total score to merge all piles into one pile.

4
1
1
1
1
8

Hint

N40000,ai200 N \leq 40000, a_i \leq 200

Please note the range of NN (a hint from the uploader).

Translated by ChatGPT 5