The idea of solving the problem of dynamic programming with generics

Source: Internet
Author: User

Written in front: the author will participate in 16 Beijing University summer ACM training, considering to get a better learning effect, the author of this column for the 15 years to organize the training courseware and materials. Considering the time is very limited (one months), coupled with the exam, it is difficult to do each topic are combined with sample code, so the author is more familiar with the topic (DP, number theory, combination, game) mainly to organize ideas and methods, for the topic has not been studied to establish a nude model-based.

A generic approach to solving problems using dynamic programming:

1. Decompose the original problem into sub-problems
? The original problem is decomposed into several sub-problems, the sub-problem and the original problem form the same or similar, but the size becomes smaller. Sub-problems are solved, the original problem is solved (digital triangle example). Once the solution of a sub-problem is found, it is saved, so each sub-problem is solved only once.

2. Determine the status
? When solving problems with dynamic programming, we often refer to a set of variables related to sub-problems as a "state". A "state" corresponds to one or more sub-problems, the so-called "state" under the "value" is the "state" corresponding to the sub-problem of the solution.
A collection of all "states" that constitute the "state space" of the problem. The size of the state space is directly related to the time complexity of solving the problem with dynamic planning.         In the example of a digital triangle, there is a total of NX (N+1)/2 numbers, so there is a total of NX (N+1)/2 states in the state space of this problem.             The time complexity of the whole problem is the number of States multiplied by the time it takes to calculate each state. Each "state" in a digital triangle takes only one pass, and the time it takes to calculate each state is a constant that is independent of N.
When solving problems with dynamic programming, it is often encountered that K integer variables can form a state (such as the line number and column number in a number triangle, which constitute "state"). If the value range of this k integer variable is N1, N2, ... Nk, then, we can use a k-dimensional array array[n1] [N2] ... [Nk] to store "values" for each state. This "value" is not necessarily an integer or a floating-point number, it may need a structure to represent, then the array can be an array of structures. A "value" under a "state" is usually the solution to one or more sub-problems.

3. Determine the values of some initial states (boundary States)
In the case of "digital triangles", the initial state is the bottom number, and the value is the bottom digit value.
4. Determine the state transition equation
By defining what is "state" and "value" under that state, find out how different states are migrated-that is, how to get the "value" of another "state" ("Everyone is Me" recursive) from one or more known "states" of value. The migration of States can be expressed by recursive formulas, which can also be called "state transition Equations".

Characteristics of the problem that can be solved by the dynamic regulation
1) The problem has the optimal substructure property. If the optimal solution of the problem contains the solution of sub-problems is also optimal, we call this problem has the best sub-structure properties.

2) No effect. Once the current number of status values is determined, then the evolution of the process is only related to the values of the several states, and it does not matter which method was taken before or which path evolved to the current state.

The idea of solving the problem of dynamic programming with generics

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.