爬楼梯

题源:leetcode

链接:https://leetcode-cn.com/problems/climbing-stairs/

 这也是道简单的动态规划题,状态转移方程为:f(x) = f(x-1)+f(x-2)

 1 class Solution {
 2 public:
 3     int climbStairs(int n) {
 4         int p = 0;
 5         int q = 0;
 6         int r = 1;
 7 
 8         for(int i = 0; i < n; i++){
 9             p = q;
10             q = r;
11             r = p+q;
12         }
13         return r;
14     }
15 };
原文地址:https://www.cnblogs.com/hosheazhang/p/15060532.html