小明刚刚看完电影《第39级台阶》,离开电影院的时候,他数了数礼堂前的台阶数,恰好是39级!
站在台阶前,他突然又想着一个问题:
如果我每一步只能迈上1个或2个台阶。先迈左脚,然后左右交替,最后一步是迈右脚,也就是说一共要走偶数步。那么,上完39级台阶,有多少种不同的上法呢?
public class Main {
static int count=0;
public static void main(String[] args) {
Dfs(0,0);
System.out.print(count);
}
public static void Dfs(int deep,int step){
if(deep>39)return;
if(deep==39){
if(step%2==0){
++count;
}
}else{
Dfs(deep+1,step+1);
Dfs(deep+2,step+1);
}
}
}