Investment issues:
Problem Description: There is m yuan, investment in the project of N, F (x): The value of the X-element into the first project. Maximize the overall benefit of the investment program. (This problem is not easy, this is the first time I did not see the answer to make a dynamic planning problems, it should have taken three hours).
Modeling: The solution of the problem is vector <x1,x2,xn>
Objective function: MAX{F1 (x1) +f2 (x2) +fn (xn)}
For sub-problem partitioning and Calculation order:
K: Consider investment in project,,, K
X: Total amount cannot exceed X
Raw input, k=n, x=m
K=1 to N
X=1 to M
Suppose there is a $50,000 investment that can be invested in four projects, the return on investment form is as follows:
Tips for dynamic Programming Beginner code:
1. For memos in dynamic planning, the so-called stored data structures are often applied in the form of matrices, and sometimes the input also has matrices:
For matrices, the most important: be sure to understand the meaning of row and column! Make sure you understand the meaning of row and column! Make sure you understand the meaning of row and column! Important thing to say three times!!!
For example, in this issue, the matrix that is used to store sub-results dp[the amount of investment [projects invested]
2. When initializing the memo, be sure to add all the items that are likely to be used after the calculation, and the F (0) column will be used in the subsequent calculations, so the memo to be added to the DP
3. The state transition equation has a relationship not only in numerical values, but also in the subscript of a memo: for example: max = Dp[j-k][i-1]+item[k][i]
For the solution to this problem:
1. The memo table contains row rows, column columns, rows representing the amount of money invested, and the total amount of items required to invest, total row*column
XK have x+1 possible values, calculate f[k][x] (2<=k<=n, 1<=x<=m) need:
X+1 Times Addition
X-Times Comparison
The following table is a memo generated through dynamic planning:
Dynamic planning of investment issues:
1. Define sub-problems with two different types of parameters
2. List the recursive equations and initial values of the optimization function
3. Determining the order of sub-problems calculation
4. Calculate the complexity of time
Reference code:
Algorithm learning--Dynamic Programming 2