zoukankan      html  css  js  c++  java
  • 变态跳台阶

    题目:一只青蛙一次可以跳上1级台阶,也可以跳上2级……它也可以跳上n级。求该青蛙跳上一个n级的台阶总共有多少种跳法

    思路:该题是上一题的加强版,也通过类似的思路分析

    f(1) = 1

    f(2) = f(2-1) + f(2-2)         //f(2-2) 表示2阶一次跳2阶的次数。

    f(3) = f(3-1) + f(3-2) + f(3-3) 

    ...

    f(n) = f(n-1) + f(n-2) + f(n-3) + ... + f(n-(n-1)) + f(n-n) 

                  | 1       ,(n=0 ) 

    f(n) =     | 1       ,(n=1 )

                  | 2*f(n-1),(n>=2)
     public int JumpFloorII(int target) {
            if(target==0) return 0;
           return (int)Math.pow(2,target-1);
        }
  • 相关阅读:
    qsort
    strcmp
    LotteryDrawing
    retire or not retire ? is a question.
    alloc && afree
    strlen
    c point
    c point ccccc
    MySQL MGR源码分析2
    MySQL MGR实现分析
  • 原文地址:https://www.cnblogs.com/team42/p/6681267.html
Copyright © 2011-2022 走看看