当前位置:网站首页>12. Monkeys climb mountains

12. Monkeys climb mountains

2022-04-23 06:08:00 linsa_ pursuer

One day, a monkey wanted to climb from the foot of the mountain to the top of the mountain , On the way, there is a N A staircase of steps , But the monkey has a habit : You can only jump at a time 1 Step or jump 3 Step , How many different ways do monkeys jump through this ladder ?

Input
Enter only one integer N(0<N<=50) How many steps does this ladder have
Output
How many jump modes are output ( Number of solutions )

package com;

import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        System.out.println(jump(s.nextInt()));
    }

    public static int jump(int num){
       if(num<3){
           return 1;
       }
       return jump(num-1)+jump(num-3);
    }

}

Such as :

Input :
3
50
Output :
2
 

版权声明
本文为[linsa_ pursuer]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/04/202204220533259581.html