Title Description
Description
In a garden-shaped playground surrounded by n heap of stones, it is necessary to merge the stones into a pile in sequence. The rule is that only the adjacent 2 stacks are merged into a new pile each time, and a new pile of stones is counted as the combined score.
In this paper, we design 1 algorithms to calculate the minimum score and the maximum score of combining n heap stones into 1 piles.
Enter a description input
Description
The 1th line of data is a positive integer n,1≤n≤100, which indicates that there are n heap stones. The 2nd line has n number, which indicates the number of stones per heap.
outputs description output
Description
Output total 2 lines, 1th behavior minimum score, 2nd behavior maximum score.
sample input to
sample
4
4 4 5 9
Sample output Sample
outputs
43
54
Turn the ring into linear, and the array opens one more times.
ANS=MIN{F[1,N],F[2,N+1],..., f[n,2n-1]}
Complexity O (n^3)
Prefixes and the like are linear, just pay attention to the cycle of anything to open to 2*n-1
code here
--This ancient hate, thousands of like, should only clutch is joys and sorrows
Copyright NOTICE: Reprint Please specify source [ametake Copyright]http://blog.csdn.net/ametake Welcome to see
"Basic Exercise" "Interval DP" codevs2102 stone merge 2 (ring)