之前遇到的青蛙是跳1层或2层,这个青蛙是1层、2层、3层的跳
import java.util.Scanner;
/**
* @author WanZi
* @create 2022-10-11 19:35
*/
//1层、2层、3层
public class Main {
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
int N = sc.nextInt();
int res = skip(N);
System.out.println(res);
}
public static int skip(int n){
if(n == 1){
return 1;
}
if(n == 2){
return 2;
}
if(n == 3){
return 4;
}
int[] dp = new int[n+1];
dp[0] = 1;
dp[1] = 1;
dp[2] = 2;
for(int i=3;i<=n;i++){
dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
}
return dp[n];
}
}