当前位置:网站首页>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 ...
边栏推荐
- VPP cannot load up status interface
- 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
- Zhou Chen, vice president of zhanrui market, responded to everything about 5g chip chunteng 510!
- 剖析kubernetes集群内部DNS解析原理
- School day (summer vacation daily question 2)
- 单点登录(一处登录,处处可用)
- ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off
- background
- CSDN编程挑战赛之数组编程问题
- sqlilabs less-28~less-8a
猜你喜欢

C编程 --“最大子数组的和” 的动态规划的解法

What are the ways to realize web digital visualization?

FinClip实现微信授权登录的三种方案

ECS is exclusive to old users, and the new purchase of the remaining 10 instances is as low as 3.6% off

JWT(json web token)

Leetcode 237. delete nodes in the linked list

sqlilabs less-29

单点登录(一处登录,处处可用)

sqlilabs less-28~less-8a

The computer accesses the Internet normally with the same network cable, and the mobile phone connects to WiFi successfully, but it cannot access the Internet
随机推荐
出于数据安全考虑,荷兰教育部要求学校暂停使用 Chrome 浏览器
Three schemes for finclip to realize wechat authorized login
Build keyword driven automated testing framework
Leetcode 204. 计数质数(太妙了)
Leetcode 0121. the best time to buy and sell stocks - simulation from back to front
Single sign on (one sign on, available everywhere)
ERA5数据集说明
Introduction summary of using unirx in unity
Typera+picgo+ Alibaba cloud OSS setup and error reporting solution [reprint]
easyrecovery免费数据恢复工具操作简单一键恢复数据
ThreadLocal
HTB-Granpa
对于von Mises distribution(冯·米塞斯分布)的一点心得
编程大杂烩(二)
新时代生产力工具——FlowUs 息流全方位评测
Game 302 of leetcode
Run length test of R language: use the runs.test function to perform run length test on binary sequence data (check whether the sequence is random)
2020ICPC 江西省赛热身赛 E.Robot Sends Red Packets(dfs)
The u-collapse component of uniapp mobile uview is highly init
基于ISO13209(OTX)实现EOL下线序列