#P1470. Pku1738 An old Stone Game

    ID: 482 传统题 1000ms 512MiB 尝试: 135 已通过: 51 难度: 9 上传者: 标签>CF2700省选/NOI-Garsia-Wachs 算法FHQ Treap 分裂合并按排名分裂LTC男人八题系列

Pku1738 An old Stone Game

题目描述

There is an old stone game. At the beginning of the game the player picks n(1≤n≤500001\leq n\leq 50000) piles of stones in a line. The goal is to merge the stones in one pile observing the following rules: At each step of the game,the player can merge two adjoining piles to a new pile.The score is the number of stones in the new pile. You are to write a program to determine the minimum of the total score.

就是最简单的石子合并问题.

输入格式

The input contains several test cases. The first line of each test case contains an integer nn(nn 等于 100100) denoting the number of piles. The following n integers describe the number of stones in each pile at the beginning of the game. The last test case is followed by one zero.

输出格式

For each test case output the answer on a single line. You may assume the answer will not exceed 10910^9.

1
100
3
3 4 3
4
1 1 1 1
0
0
17
8

题目来源

LTC男人八题系列