当前位置:网站首页>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
};
边栏推荐
- log4j的详情配置
- The GLM function of R language is used to build a binary logistic regression model (the family parameter is binomial), and the AIC function is used to compare the AIC values of the two models (simple
- Topic38——56. Consolidation interval
- How histrix works
- AI for Science:科研范式、开源平台和产业形态
- hibernate操作oracle数据库 主键自增
- 56. Core principle of flutter - flutter startup process and rendering pipeline
- Fork/Join 框架基本使用和原理
- Neo4j:入门基础(一)之安装与使用
- Two usages of enumeration classes
猜你喜欢

浏览器cookie转selenium cookie登录

AI for Science:科研范式、开源平台和产业形态

How to find the movie and TV clips with the same lines? These 8 movies search for artifact, and find the corresponding segment in one line

MapReduce practical cases (customized sorting, secondary sorting, grouping, zoning)

私藏干货分享:关于企业架构中如何进行平台化

Jwas: a Bayesian based GWAS and GS software developed by Julia

Tidb 6.0: making Tso more efficient tidb Book rush

Unlock the secret of C language key words (issue 6)

动态规划【四】(计数类dp)例题:整数划分

面试突击60:什么情况会导致 MySQL 索引失效?
随机推荐
Comment modifier Node Fichiers dans les modules
Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022
Browser cookie to selenium cookie login
application.properties 的配置信息
2022ciscn central China Web
Deep understanding of happens before principle
Interview shock 60: what will cause MySQL index invalidation?
MapReduce principle analysis (in-depth source code)
Write it down once Net analysis of a property management background service stuck
自学ADT和OOP
picocli-入门
log4j.properties的配置详解
Dynamic programming [4] (counting class DP) example: integer partition
面试突击60:什么情况会导致 MySQL 索引失效?
Master formula
.NET6接入Skywalking链路追踪完整流程
How to modify a node_ Files in modules
Mit6.031 software construction7 reading notesdesigning specifications
Wechat applet realizes five-star evaluation
TiDB 6.0:让 TSO 更高效丨TiDB Book Rush