"Basic Exercise" "Interval DP" codevs2102 stone merge 2 (ring)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.