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);
}

}
原文地址:https://www.cnblogs.com/ttaall/p/14558058.html