/**
* TODO
*
* @author
* @version 1.0
* @date 2022/3/19 15:08
* 小白上楼梯
* 就站在楼梯顶部进项考虑,可以跨一步上来,可以跨两步上来,可以跨三步上来
* T(N)=t(n-1)+t(n-2)+t(n-3)
*/
public class UpFloorTest {
public static void main(String[] args) {
Scanner scanner = new Scanner(System.in);
while (true) {
int num = scanner.nextInt();
System.out.println(floor(num));
}
}
static int floor(int n) {
if (n == 0) return 1;
if (n == 1) return 1;
if (n == 2) return 2;
return floor(n - 1) + floor(n - 2) + floor(n - 3);
}
}
“相关推荐”对你有帮助么?
-
非常没帮助
-
没帮助
-
一般
-
有帮助
-
非常有帮助
提交