当前位置:网站首页>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 ...
边栏推荐
- [typescript manual]
- Tips for downloading videos in batches
- R language ggpubr package ggarrange function combines multiple images and annotates_ Figure add annotation, annotation, annotation information for the combined image, and use the right parameter to ad
- Openfegin remote call lost request header problem
- HTB-Optimum
- 剑指offer专项突击版第9天
- VIM search and replacement and the use of regular expressions
- R language obtains the data row where the nth maximum value of the specified data column is located in the data.table data
- Single sign on (one sign on, available everywhere)
- 编程大杂烩(二)
猜你喜欢

Microservice - remote invocation (feign component)

easyrecovery免费数据恢复工具操作简单一键恢复数据

Programming hodgepodge (I)

Unity接入ChartAndGraph图表插件

odoo14 | 关于状态栏statusbar关键词使用后显示异常及解决方法

Realsense D435i 深度图优化_高精度模式

新时代生产力工具——FlowUs 息流全方位评测

Three schemes for finclip to realize wechat authorized login

JWT(json web token)

Working principle and precautions of bubble water level gauge
随机推荐
弹性布局总结
编程大杂烩(一)
G1 garbage collector
Unity accesses chartandgraph chart plug-in
JWT(json web token)
background
LCP plug-in creates peer-to-peer 802.1ad interface
Realsense D435i 深度图优化_高精度模式
Continuous maximum sum and judgement palindrome
50:第五章:开发admin管理服务:3:开发【查询admin用户名是否已存在,接口】;(这个接口需要登录时才能调用;所以我们编写了拦截器,让其拦截请求,判断用户是否是登录状态;)
HTB-Devel
SystemVerilog中interface(接口)介绍
The price is 17300! Why does Huawei mate x face Samsung fold?
background
Realsense d435i depth map optimization_ High precision mode
OpenFegin远程调用丢失请求头问题
Array programming problem of CSDN programming challenge
HTB-Optimum
School day (summer vacation daily question 2)
HTB-Beep