Algorithm design and analysis - Dynamic Programming

First, the understanding of the dynamic programming algorithm

  Dynamic programming algorithm to divide and conquer is very similar to the original problem in common is broken down into several sub-problems, the solution of the original problem and then found by the sub-problems. The difference is between sub-problem of dynamic programming is not independent of each other, often overlapping. So in order to avoid double counting, you can create a table to record the child's problem has been solved, when faced with a problem child again, look-up table to get the answer. The algorithm is generally used to solve the problem with most properties, and which also has optimal subproblems and overlapping nature, i.e. the nature of the overlapping nature of the substructure and the optimal sub-problems.

  The basic steps to solve this kind of problem with dynamic programming algorithm is:

1, to find the optimal solution of the nature and structure of 2 to establish the optimal value of the sub-problems recursively relationship (i.e., write the recursive equation) 3, to calculate the optimal value of the bottom-up recursive form (may be a top-down , i.e. memo method) 4. the optimal solution of the problem is necessary to obtain the optimal solution is to set up the optimal value solution, can record information obtained in the third step.

 

Second, the recursive equation

1. The longest monotonic sequences composed of n is incremented by the number of sequences.

Recurrence equation: len [i] = max (len [j] + 1) (0 <j <i), len [i] represents the longest sequence of monotonically from a first to i-th number is incremented sequence consisting of length

2. Yangtze River Yacht Club on the set of n Yangtze yacht rental stations 1,2, ..., n. Visitors can rent a yacht in these yacht rental station and return the yacht in any boat rental station downstream. Yacht rental station i to rent rental boats between the station j is r (i, j), 1 <= i <j <= n. Try to design an algorithm to calculate the minimum required to rent rental station n from boat to boat 1 rental station.

Recurrence equation: rent [i] [j] = min (rent [i] [k] + rent [k] [j]), (i <k <= j), rent [i] [j] denotes the i-th a rental station to the j-th rental stations required minimum rent

 

Third, the programming of pair

This pair programming several very good situation, communicate with each other, they can be programmed to detect and solve problems, higher efficiency.

 

 

Guess you like

Origin www.cnblogs.com/Jettle/p/11788021.html