当前位置:网站首页>Dynamic planning learning notes
Dynamic planning learning notes
2022-07-25 05:40:00 【lsely】
Dynamic programming learning notes
List of articles
Dynamic programming
Fibonacci sequence
Fibonacci sequence Every number All are The sum of the first two digits of this number .
Fibonaccci Sequence
1 1 2 3 5 8 13 21
If we use a formula to represent any number in the sequence, it is (n>1):
f i b ( n ) = f i b ( n − 1 ) + f i b ( n − 2 ) fib(n) = fib(n-1) + fib(n-2) fib(n)=fib(n−1)+fib(n−2)
In code :
long long fib(long long n){ // Find the... In the Fibonacci sequence n Number
if(n==1||n==2){
return n;
}
return fib(n-1)+fib(n-2); // Continue to recursive
}
But when n large , Amount of computation It's just Extremely large , When we decompose each calculation of the computer, we will find many Repeat the calculation , And the larger the calculation , The more calculations are repeated , Then we have to use a method : Dynamic programming .
Dynamic programming
Dynamic programming Is the opposite solution Optimization problems A kind of Design method or thought , It's not an algorithm , This method contains many algorithms , Such as recursive , decompose etc. . Dynamic programming solves more complex problems by decomposing the original problem into several sub problems .
One type, three signs
There are many people who are interested in Dynamic programming such Optimization plan Understand very thoroughly and make a summary , I summarize it as **“ One type, three signs ”**.
" Type I ” It refers to The optimal solution model .
“ Three signs ” refer to Optimal substructure 、 Subsequent invalidity and Memory search .
Optimization plan
First simulate a scenario : The teacher arranged 100 A very complicated problem , But this 100 All the questions are the same , Then we only need to calculate the result of one problem , Just copy it to other questions ( Of course, you can also calculate one by one , But a person who really counts one by one must be a fool —), And unfortunately , The computer is such a fool —, And then we can use it Memory search , Is to record the results of each calculation , If you need a certain calculation result in the subsequent calculation , Call directly .
// Use dynamic programming to solve Fibonacci sequence
long long fib(long long n,long long* memo) {
if (n == 1 || n == 2) return 1;
if (memo[n] != 0) return memo[n];
memo[n] = fib(n - 1, memo) + fib(n - 2, memo);
return memo[n];
}
summary :
The focus of Dynamic Planning :
1. decompose , Decompose the original problem into several sub problems .
2. One type, three signs , Make an optimal solution model for the problem , At a certain stage, once determined , It will not be affected by the later stage and memory search .
... Here is the end , Here is the end ...
边栏推荐
- npx和npm区别
- 求求你别再用 System.currentTimeMillis() 统计代码耗时了,真的太 Low 了!
- 2021 ICPC Shaanxi warm up match b.code (bit operation)
- Openfegin remote call lost request header problem
- PostgreSQL learning 04 PG_ hint_ Plan installation and use, SQL optimization knowledge
- The difference between $write and $display in SystemVerilog
- Summary of common attributes of flex layout
- Common methods of JS operation array
- VPP不能加载UP状态接口
- Tips for downloading videos in batches
猜你喜欢
随机推荐
background
剑指offer专项突击版第9天
After Oracle user a deletes a table under user B's name, can user B recover the deleted table through the recycle bin?
Analyzing the principle of DNS resolution in kubernetes cluster
sqlilabs less-28~less-8a
Array programming problem of CSDN programming challenge
Build keyword driven automated testing framework
Flexible layout summary
ABC 261.D - Flipping and Bonus ( DP )
Basset: learning the regulatory code of the accessible genome with deep convolutional neural network
typora+PicGo+阿里云OSS 搭建以及报错解决【转载】
New discovery of ROS callback function
50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
HTB-Granpa
Base64 (conversion between string and Base64 string)
R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
聊聊 Redis 是如何进行请求处理
For data security reasons, the Dutch Ministry of Education asked schools to suspend the use of Chrome browser
Programming hodgepodge (II)
[typescript manual]








