当前位置:网站首页>First encounter with dynamic programming
First encounter with dynamic programming
2022-06-27 12:23:00 【zhen12321】
- You are the guiding algorithm of how to go in every step of my life
- Mathematically, I call you an ugly mathematical induction , namely k<n-1&&k=n-1 To k<=n The process of .
- State shift , Repeat the question , The optimal substructure is your core .
- You always rely on violent algorithms first .
- It makes ordinary people feel like listing a formula , How to invert parameters step by step , Then the method of finding the optimal solution in this binary result set .
- Memos are your most common weapon , After using it , You are a different person , Time complexity can reach O(n), It's a tree , However, the complexity is so low .
- Many people misunderstand you , Think you are recursive , Recursion, however, is a dead end traversal , Your state transition needs a little semantic comfort .
- You are from the bottom up . From top to bottom tells us to traverse violently from the top . Bottom up is a result of design , And I got an equation that shifts this result , Gradually transfer from the top to the bottom .
Classical problems , climb stairs
Suppose you're climbing the stairs . need n You can reach the top of the building .
Every time you climb 1 or 2 A stair . How many different ways can you climb to the top of the building ?
/** * @param {number} n * @return {number} */
var climbStairs = function(n) {
// clear dp Array , So-called dp, Is the abbreviation of dynamic programming .
var dp=[]
// clear dp Bounds of an array , That is the starting point of our deduction .
dp[1]=1;
dp[2]=2;
// Specially defined variable names , be called tz, The meaning of transfer . there tz The pointer represents 『 state 』 The transfer of .
var tz = 3;// from 3 At first, it can only climb 1 Step , or 2 Step . The third step is to 「 Calculation 」 了 .
// I want to climb n rank , I just want to move to n That's all right. .
while(tz<=n){
dp[tz]=dp[tz-1]+dp[tz-2]; //【 State transition equation 】
tz++;
}
return dp[n]; // Return the result I want
};
边栏推荐
- Wechat applet payment password input
- 居家办公被催之后才明白的时间管理
- application.properties 的配置信息
- Two usages of enumeration classes
- build.gradle 配置
- nifi从入门到实战(保姆级教程)——身份认证
- 树莓派 3b+ 学习
- i. Construction of mx6ull C language environment
- 行业洞察 | 新零售业态下,品牌电商应如何重塑增长?
- R language uses the poisgof function of epidisplay package to test the goodness of fit of Poisson regression and whether there is overdispersion
猜你喜欢

Minimum editing distance (linear DP writing method)

Topic37——64. 最小路径和
![Dynamic programming [4] (counting class DP) example: integer partition](/img/06/4b3863bbb85582348c6f4ea7c5511e.png)
Dynamic programming [4] (counting class DP) example: integer partition

Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022

uniapp下拉弹层选择框效果demo(整理)

On ticheck

全球最强截图软件 Snipaste

DM8:达梦数据库-锁超时

面试突击60:什么情况会导致 MySQL 索引失效?

Uniapp drop-down layer selection box effect demo (sorting)
随机推荐
盘点一些好用且小众的 Markdown 编辑器
如何修改 node_modules 裏的文件
namespace ‘rlang’ 0.2.0 is being loaded, but &gt;= 0.3.0 is required
Deep understanding of happens before principle
Master formula
面试突击60:什么情况会导致 MySQL 索引失效?
word文本框换页
自学ADT和OOP
Don't miss it. New media operates 15 treasure official account to share
怎么找相同台词的影视片段?这8个电影搜索神器,一句台词找到对应片段
想学好C语言,操作符也很重要
Detailed configuration of log4j
Minimum editing distance (linear DP writing method)
Hands on API development
面试突击60:什么情况会导致 MySQL 索引失效?
i. Construction of mx6ull C language environment
esp32s3 IPERF例程测试 esp32s3吞吐量测试
Self taught ADT and OOP
build.gradle 配置
Nifi from introduction to practice (nanny level tutorial) - identity authentication