• Leecode no.? 兔子跳台阶


    package leecode;

    /**
    *
    * 一共n层台阶,小兔子每次跳1-n个台阶,有多少种可能
    * 分别打印出这些情况
    *
    * 这题是大三懵懂少年时候笔试被虐的 一直耿耿于怀,今天翻出来搞一搞
    */
    public class RabbitJump {
    static int count = 0;

    /**
    *
    * @param last 还剩多少个台阶
    */
    public void jump(int last, StringBuffer stringBuffer){
    if(last == 0){
    count++;
    System.out.println("第"+count+ "种可能:"+ stringBuffer.toString());
    return;
    }

    //兔子下一跳可能跳的台阶数
    for(int i = 1; i <= last; i++){
    stringBuffer.append(i+"步 ");
    jump(last - i, stringBuffer);
    stringBuffer = new StringBuffer();
    }
    }

    public static void main(String[] args) {
    new RabbitJump().jump(3, new StringBuffer());
    System.out.println(count);
    }

    }
  • 相关阅读:
    常用的JS代码
    静态类相关
    并查集
    RMQ
    模考题line
    递归模考题 集合
    KMP
    快速幂
    读现代软件工程之构建之法的疑问
    实验二
  • 原文地址:https://www.cnblogs.com/ttaall/p/14558058.html
Copyright © 2020-2023  润新知