当前位置:网站首页>[idea] dynamic planning (DP)
[idea] dynamic planning (DP)
2022-06-24 16:21:00 【Xiaochengxin post station】
One 、 Introduce
1.1、 history
Simply remember ,20 century 50 American mathematician Richard in the s · Invented by Behrman , It is an important tool for solving some optimal problems in mathematics , And in the computer field as a general algorithm design technology . For the rest of the history, please refer to MIT textbooks Dynamic Programming Part 1 .
1.2、 Definition
【 a key 】 If the problem is caused by Overlapping subproblems Composed of , Then we can use dynamic programming technology to solve it .
Generally speaking , The subproblem appears in the recurrence relation of solving a given problem , This recurrence relation contains the solutions of the same type of more sub problems .DP It is suggested to solve the overlapping subproblems again and again , It is better to solve each smaller subproblem only once and record the results in the table , In this way, the solution of the original problem can be obtained from the table .
1.3、 Familiar with mathematical applications
Classical problems of Fibonacci numbers
0,1,1,2,3,5,8,13,21,34....
What is the law that we can find out ?
【0】= 0,【1】=1,【2】=1,【3】=2,【4】=3
Disassemble the problem , Find overlapping sub problems ( Color area ), According to our definition , If the problem is composed of overlapping subproblems , Then we can use dynamic programming technology to solve .
Then we define the subproblem, for example, we ask F(n)=F(n-1)+F(n-2), Then guess whether all the results are satisfied according to our formula . Find out n=0/1 When , dissatisfaction . So we need to adjust the formula . The following pseudo code :
function(int n){
// Recursive exit condition
if (n < 1){
return n;
}else{
// recursive
return function(n-1)+function(n-2);
}
}But the problem we mentioned earlier , In essence, our recursive code above has already realized the basic functions , According to the above figure, we calculate F(4) When , Need to compute F(3) and F(2), But many overlapping subproblems are found , How to solve double counting ? We can assume that whatever F(2) and F(3) Who will execute first , Keep the results of the previous execution in memory , Then you can directly obtain the following information when performing the calculation , So you can avoid double counting . Let's modify the pseudo code :
mem = {}
function(int n){
// Memorize , Avoid solving calculations repeatedly
if(n in mem) return mem[n];
// Recursive exit condition
if (0 <= n < 1){
return n;
}else{
// The solution of memory storage subproblem
mem[n] = function(n-1)+function(n-2);
// recursive
return function(n-1)+function(n-2);
}
}So how was the original problem solved ? In fact, we use the bottom-up logic when n=0/1 When , Start computing from the recursive stack , Until the result .
Two 、 Step suggestions
2.1、 Dynamic planning steps 5
- Define subproblems ( Personal understanding is to disassemble the problem first , Disassembly to the smallest unit is the subproblem )
- guess ( Part of the solution , Derive the calculation formula )
- Solutions to related sub problems ( Solutions to local problems )
- recursive + memory ( Solve the problem of double counting )
- Or build DP The table checks the loop of sub problems from bottom to top / Topological order ( State transition equation )
- Solve the original problem := Solve subproblems or by combining subproblems => Extra time
source : MIT derived steps for dynamic programming , Dynamic Programming Part 1 , Dynamic Programming Part II
2.2、 Refine next step
1、 Define subproblems - Problem disassembly
2、 Building recursive formulas ( recursive + Memorize ==> Recurrence )
3、 Bottom up treatment ( State transition equation )
4、DP ≈ recursive + Memorize + guess
3、 ... and 、 Learning route
- Currency maximization
- Coin change problem ( Greedy Algorithm )
- Coin collection
- Recurrence of violence ( Greedy failure )
- Avoid recursive double counting ( Recurrence = recursive + Memorize )
- knapsack problem
- Completely backpack
- Subarray problem
- Subsequence problem
- Buying and selling stocks
- The longest increasing subsequence problem
- Maximum subarray problem
- Optimal substructure and state dependence
This paper explains the deduction of the idea of dynamic programming and the path of learning and practice , The following will add practical algorithm topics !
边栏推荐
- Istio FAQ: virtualservice route matching sequence
- Several common DoS attacks
- 对深度可分离卷积、分组卷积、扩张卷积、转置卷积(反卷积)的理解
- Little red book, hovering on the edge of listing
- 存在安全隐患 部分冒险家混动版将召回
- 基于STM32的MD5校验
- Product level design of a project in SAP mm
- Ui- first lesson
- Understanding of deep separable convolution, block convolution, extended convolution, transposed convolution (deconvolution)
- Global and Chinese market of training dance clothes 2022-2028: Research Report on technology, participants, trends, market size and share
猜你喜欢

Problems encountered in the work of product manager

ZOJ - 4104 sequence in the pocket

微信公众号调试与Natapp环境搭建

【面试高频题】难度 3/5,可直接构造的序列 DP 题

构建Go命令行程序工具链

C. Three displays(动态规划)Codeforces Round #485 (Div. 2)
![[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction](/img/32/720ffa63a90cd5d37460face3fde38.png)
[interview high frequency questions] sequential DP questions with difficulty of 3/5 and direct construction

ZOJ——4104 Sequence in the Pocket(思维问题)

Cap: multiple attention mechanism, interesting fine-grained classification scheme | AAAI 2021

Logging is not as simple as you think
随机推荐
2021-04-18: given a two-dimensional array matrix, the value in it is either 1 or 0,
【prometheus】1. Monitoring overview
Several common DoS attacks
Global and Chinese market of inverted syrup 2022-2028: Research Report on technology, participants, trends, market size and share
Inter thread communication of embedded development foundation
Enterprise security attack surface analysis tool
[golang] Introduction to golang (I) establishment of running environment
Installer la Bibliothèque imagemagick 7.1 et l'extension imagick de PHP
ZOJ - 4104 sequence in the pocket
Interpretation of swin transformer source code
Golang+redis reentrant lock
C. K-th not divisible by n (Mathematics + thinking) codeforces round 640 (Div. 4)
Remain true to our original aspiration
Web page live broadcast on demand RTMP streaming platform easydss newly added virtual live broadcast support dash streaming function
How to open a futures account safely? Which futures companies are more reliable?
Bitwise Operators
Percona Toolkit series - Pt deadlock logger
There are potential safety hazards Land Rover recalls some hybrid vehicles
Wechat official account debugging and natapp environment building
Istio FAQ: sidecar stop sequence