"Algorithmic Learning Notes" 84. Sequence DP relaxation + cost processing code_vs 1048 Stone Merge

Source: Internet
Author: User

Simple DP, when processing as far as possible with Len from 1 to N), I from 1 to len-n] to traverse.

Note that Len at this time represents a sequence of Len elements after the start of I

 for (int i = n1; I >=1 ;---i)    {for (int j = i+1; j < = N; + +J)        {= INF        ;  for (int k = i; k < J; + +k)            {= min (Dp[i][j], dp[i][k] + dp[k+1][j] + weight (i,j ) );        }    }}

Note First initialize DP[I][J] as inf

K Insert from I to J

The cost of dividing the I.J into [i,k] and [k+1,j] (slack handling) Two segment two is the total weight

The last dp[1][n] is the answer.

"Algorithmic Learning Notes" 84. Sequence DP relaxation + cost processing code_vs 1048 Stone Merge

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.