当前位置:网站首页>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
};
边栏推荐
- Configuration of YML
- Master formula
- The R language uses the DOTPLOT function of epidisplay package to visualize the frequency of data points in different intervals in the form of point graph, specifies the grouping parameters with the b
- What's the matter with Amazon's evaluation dropping and failing to stay? How to deal with it?
- Wechat applet realizes five-star evaluation
- Thinkphp6 interface limits user access frequency
- Getting started with go web programming: validators
- [on Nacos] get started quickly
- $15.8 billion! 2021 the world's top15 most profitable hedge fund giant
- Custom multithreading base class threading Event
猜你喜欢

Comment modifier Node Fichiers dans les modules

Online bidding of Oracle project management system

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

JMETER连接DM8

Minimum editing distance (linear DP writing method)

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

How to participate in openharmony code contribution

Research Report on the overall scale, major manufacturers, major regions, products and application segments of hydraulic torque in the global market in 2022
![Dynamic programming [III] (interval DP) stone merging](/img/a4/82c4d63b8df5d092a96b80dd497147.jpg)
Dynamic programming [III] (interval DP) stone merging
![[on Nacos] get started quickly](/img/cc/af4ab640952b880595a89f66688ff5.jpg)
[on Nacos] get started quickly
随机推荐
和动态规划的第一次相遇
Comment modifier Node Fichiers dans les modules
dried food! What problems will the intelligent management of retail industry encounter? It is enough to understand this article
[high frequency interview questions] difficulty 1.5/5, LCS template questions
namespace ‘rlang’ 0.2.0 is being loaded, but &gt;= 0.3.0 is required
关于枚举类的两种用法
MapReduce实战小案例(自定义排序、二次排序、分组、分区)
Go Web 编程入门:验证器
Topic37——64. 最小路径和
Nifi from introduction to practice (nanny level tutorial) - identity authentication
Object serialization
2022ciscn central China Web
In 2021, the global enhanced oil production surfactant revenue was about USD 202.3 million, and it is expected to reach USD 297.1 million in 2028
Histrix工作原理
动态规划【三】(区间dp)石子合并
Safe landing practice of software supply chain under salesforce containerized ISV scenario
build.gradle 配置
Wechat applet realizes five-star evaluation
微服务拆分
浏览器cookie转selenium cookie登录