博文中会简要介绍Leetcode P0070题目分析及解题思路。
“Climbing Stairs”是很经典的动态规划问题,很多动态规划问题的原型都是这道题,例如p0062和p0063。这道题相对简单,递推表达式也比较容易想到。
You are climbing a stair case. It takes n steps to reach to the top.
Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top?
这道题的递推式如下:
以下是Java的题解代码实现。
以下是C++的题解代码实现。