Dynamic Programming algorithm

Source: Internet
Author: User

The basic idea: to decompose the problem into several sub-problems, similar to the Division method, but note that the sub-problems of the dynamic programming may not be independent, and the sub-problems of the divide-and-conquer method are independent

The sub-problems in dynamic programming are usually overlapping, that is, the solution of a sub-problem is based on the solution of another sub-problem, and the solution of the pair problem is stored to avoid the repeated computation.

Applicable case: 1, to find the best solution

2. The current state is irrelevant to the future

3, overlapping sub-problem (dynamic planning of the advantages of the embodiment)

Key: Identify three elements: 1, the stage of the problem, 2, the state of each stage, 3, the recurrence relationship from the former stage to the back stage

vi. Dynamic Programming algorithm basic framework copy code code1  for(j=1; j<=m; j=j+1)//First Stage 2XN[J] =initial value;3  4   for(i=n-1; i>=1; i=i-1)//other stages of n-1 5     for(j=1; J>=f (i); j=j+1)//f (i) expressions in relation to I 6Xi[j]=j=max (or min) {g (xi-1[J1:j2]), ..., G (xi-1[jk:jk+1])}; 8  9t = g (x1[j1:j2]);//A scheme for solving the optimal solution of the whole problem by the optimal solution of sub-problemTen  Oneprint (x1[j1]); A  -  for(i=2; i<=n-1; i=i+1) the {   -t = t-xi-1[Ji]; -  +       for(j=1; J>=f (i); j=j+1) +         if(t=Xi[ji]) at               Break;}

Knapsack Problem Solving

1, the best matrix fill

2. Attention to boundary conditions

3. Finding the optimal solution in the matrix

Dynamic Programming algorithm

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.