#P1880. [NOI1995] 石子合并

    ID: 832 远端评测题 1000ms 125MiB 尝试: 2 已通过: 1 难度: 6 上传者: 标签>动态规划,dp2001NOI 系列区间 dp四边形不等式

[NOI1995] 石子合并

Description

Along the circumference of a circular track, there are NN 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 NN piles into 11 pile.

Input Format

The first line contains the positive integer NN, the number of piles.

The second line contains NN integers; the ii-th integer aia_i denotes the number of stones in the ii-th pile.

Output Format

Output a total of 22 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: 1N1001 \leq N \leq 100, 0ai200 \leq a_i \leq 20.

Translated by ChatGPT 5