第39阶台阶

第39阶台阶
小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!
站在台阶前,他突然又想着一个问题:
如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多
少种不同的上法呢?
请你利用计算机的优势,帮助小明寻找答案。
要求提交的是一个整数。
注意:不要提交解答过程,或其它的辅助说明文字。

public class 第39阶台阶 {
static int count = 0;

public static void main(String[] args) {
	// TODO Auto-generated method stub
	f(39, 0);
	System.out.println(count);
}

// n:剩下的阶梯数
// step:已走的步数
static void f(int n, int step) {
	if (n < 0)
		return;
	if (n == 0 && step % 2 == 0)
		count++;
	f(n - 1, step + 1);
	f(n - 2, step + 1);
}

}

猜你喜欢

转载自blog.csdn.net/weixin_42487387/article/details/88290660