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