package youling.studio.test;
import java.util.concurrent.atomic.AtomicInteger;
public class Test07 {
private AtomicInteger count = new AtomicInteger(0);
public static void main(String[] args) {
int n = 20;
Test07 t = new Test07();
t.walk(n);
System.out.println(t.count.get());
}
public void walk(int n) {
if(n>3) {
walk(n-1);
walk(n-2);
walk(n-3);
}else if(n==3) {
this.count.getAndIncrement();
walk(n-1);
walk(n-2);
}else if(n==2) {
this.count.getAndIncrement();
walk(n-1);
}else {
this.count.getAndIncrement();
return;
}
}
}
递归终止条件:剩余台阶数为1的时候,此时只有一种选择.
走法界定:只有当前剩余值,可能刚好是一种走法的补数的时候,对走法进行加1操作.