LeetCode 746. Min Cost Climbing Stairs

On a staircase, the i-th step has some non-negative cost cost[i] assigned (0 indexed).

Once you pay the cost, you can either climb one or two steps. You need to find minimum cost to reach the top of the floor, and you can either start from the step with index 0, or the step with index 1.

Example 1:
Input: cost = [10, 15, 20]
Output: 15
Explanation: Cheapest is start on cost[1], pay that cost and go to the top.
Example 2:
Input: cost = [1, 100, 1, 1, 1, 100, 1, 1, 100, 1]
Output: 6
Explanation: Cheapest is start on cost[0], and only step on 1s, skipping cost[3].
Note:
cost will have a length in the range [2, 1000].
Every cost[i] will be an integer in the range [0, 999].

题目大意:爬n阶的楼梯,每层都有一个cost值(0~n-1),每次可以爬1层或者2层,求爬完全程的最小花费cost(可以从第0层开始也可以从第1层开始)

分析:dp数组,每次dp[i] = cost[i] + min(dp[i-1], dp[i-2]),最终返回dp[n-1]和dp[n-2]中较小的那个~

 

[note] 隐函数求导公式的证明dy/dx=-F’x/F’y、隐函数存在定理

隐函数求导公式

它来源于隐函数存在定理1:设函数在点得某一邻域内具有连续偏导数,,则方程在点得某一邻域内能唯一确定一个连续且具有连续导数的函数,它满足条件,并有

证明过程如下:代入,得恒等式,在这个恒等式两边对求导,得,由于连续且,所以存在的一个邻域,在这个邻域内,于是得

在Windows上安装Python

  • https://www.python.org/downloads/ 上下载Python的安装包
  • 打开安装包进行安装,确保安装了 pip  并且 Python 添加到了你的 PATH
  • 开始菜单 -> 所有程序 -> Python -> IDLE编辑和运行Python代码~

Mac OSX上安装Python的方法

使用Homebrew安装python

  • 如果没有安装Homebrew,先安装Homebrew   /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)”
  • 安装完Homebrew之后,通过 brew help 检验是否安装完成
  • 输入 brew install python 安装Python 2;或 brew install python3 安装Python 3
  • python 或者 python3 进入Python Shell。使用 control + D 退出shell

使用程序包安装

  • https://www.python.org/downloads/ 下载安装包
  • Finder -> Applications -> python -> IDLE.app中编辑和运行Python代码

http状态码

200系列:OK
300系列:重定向
  • 301 永久移动
  • 302,303,307 临时重定向
  • 304  未被修改
400系列:客户端错误
  • 400 错误的请求
  • 401 未授权
  • 403 被禁止
  • 404 未找到
  • 407 需要代理授权
  • 408 请求超时
  • 409 发生冲突
  • 410 已删除
  • 426 需要升级
500系列:服务器错误
  • 502 无效的网关
  • 503 服务暂时不可用
  • 504 网关超时