当前位置:网站首页>和动态规划的第一次相遇
和动态规划的第一次相遇
2022-06-27 12:00:00 【zhen12321】
- 你是我生活中每一步怎么走的指导算法
- 数学上把你称之为丑陋的数学归纳法,即k<n-1&&k=n-1到k<=n的过程。
- 状态转移,重复子问题,最优子结构是你的核心。
- 你总是第一依赖暴力算法。
- 给普通人的感觉就像是列出一个算式,怎么把参数倒腾的一步步,然后在这个二元结果集中求最优解的办法。
- 备忘录是你最常用的利器,使用了它之后,你整个人都不一样了,时间复杂度可以达到O(n),明明是树,然而复杂度确那么低。
- 很多人对你有误解,认为你是递归,然而递归是一种没办法的遍历,你的状态转移需要一个小语义的安适。
- 你是自下而上的。自上而下告诉我们要从最高处暴力遍历。自下而上则是进行设计了一个结果,拿到了一个转移这个结果的方程,逐步从顶层向下进行转移。
经典问题,爬楼梯
假设你正在爬楼梯。需要 n 阶你才能到达楼顶。
每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢?
/** * @param {number} n * @return {number} */
var climbStairs = function(n) {
//明确dp数组,所谓dp,就是动态规划英文的缩写。
var dp=[]
//明确dp数组的边界,即我们开始推演的起始点。
dp[1]=1;
dp[2]=2;
//特意定义的变量名称,叫做tz,即转移的意思。这里的tz指针代表了『状态』的转移。
var tz = 3;//从3开始是因为它只能爬1步,或2步。第三步就需要进行「计算」了。
//我要爬n阶,我只要状态转移到n就可以了。
while(tz<=n){
dp[tz]=dp[tz-1]+dp[tz-2]; //【 状态转移方程】
tz++;
}
return dp[n]; //返回我要的结果
};
边栏推荐
- R language dplyr package arrange function sorts dataframe data, sorts dataframe data through multiple data columns, specifies the first field to be sorted in descending order, and does not specify the
- 号称史上最难618,淘宝数据盘点你做对了吗?
- Wechat applet payment password input
- Unlock the secret of C language key words (issue 6)
- Drive to APasS!使用明道云管理F1赛事
- 秒云荣获《2022爱分析 · IT运维厂商全景报告》智能运维AIOps市场代表厂商
- 如何修改 node_modules 里的文件
- 解压 .log.gz 文件
- 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
- Interview shock 60: what will cause MySQL index invalidation?
猜你喜欢

Youboxun attended the openharmony technology day to create a new generation of secure payment terminals

Raspberry pie 3b+ learning

优博讯出席OpenHarmony技术日,全新打造下一代安全支付终端

Wechat applet realizes five-star evaluation

Comment modifier Node Fichiers dans les modules

This privatized deployed enterprise knowledge base makes telecommuting a zero distance

1. Mx6ull startup mode

Drive to APasS! Use Mingdao cloud to manage F1 events

Tidb 6.0: making Tso more efficient tidb Book rush

ACL 2022 | 中科院提出TAMT:TAMT:通过下游任务无关掩码训练搜索可迁移的BERT子网络
随机推荐
Research Report on the overall scale, major producers, major regions, products and application segments of swine vaccine in the global market in 2022
Unlock the secret of C language key words (issue 6)
动态规划【三】(区间dp)石子合并
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
MIT6.031 软件构造 Reading7阅读笔记Designing Specifications(设计规范)
MySQL learning 1: installing MySQL
C/s architecture
The DBSCAN function of FPC package in R language performs density clustering analysis on data, and the plot function visualizes the clustering graph
i. Construction of mx6ull C language environment
Drive to APasS!使用明道云管理F1赛事
居家办公被催之后才明白的时间管理
Uni app sends request instructions using the escook / request miniprogram plug-in
面试突击60:什么情况会导致 MySQL 索引失效?
秒云荣获《2022爱分析 · IT运维厂商全景报告》智能运维AIOps市场代表厂商
建木持续集成平台v2.5.0发布
微服务拆分
关于枚举类的两种用法
Basic usage and principle of fork/join framework
. Net6 access skywalking link tracking complete process
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