跳台阶
package sort;
import java.util.Scanner;
/**
* @author WangXiaoeZhe
* @Date: Created in 2019/11/22 12:43
* @description:
*/
public class TaiJieSort {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int n = sc.nextInt();
System.out.println(f(n));
}
/**
* 递归方式
*/
private static int jumpFloor(int n) {
if (n <= 1) {
return 0;
}
if (n <= 2) {
return n;
}
return jumpFloor(n - 1) + jumpFloor(n - 2);
}
/**
* 动态规划
*/
public static int f(int n) {
if (n <= 0) {
return 0;
}
int f = 1;
int g = 1;
while (n-- > 0) {
g = g + f;
f = g - f;
}
return f;
}
/**
* 变态跳台阶问题(可以跳任何阶)
*/
public static int F(int n) {
if (n < 0) {
return 0;
}
if (n == 1) {
return 1;
}
int f = 1;
for (int i = 0; i <= n; i++) {
f = 2 * f;
}
return f;
}
}