fork download
  1. import java.util.Scanner;
  2.  
  3. public class Main {
  4. public static int[] F = new int[51];
  5. public static int numberOfWays(int n){
  6. F[0] = 0;
  7. F[1] = 1;
  8. F[2] = 1;
  9. F[3] = 2;
  10. F[4] = 3;
  11. if(F[n] > 0) {
  12. return F[n];
  13. } else {
  14. F[n] = numberOfWays(n-2) + numberOfWays(n-3) + numberOfWays(n-4);
  15. }
  16. return F[n];
  17. }
  18. public static void main (String[] args){
  19. Scanner sc = new Scanner(System.in);
  20. int n = sc.nextInt();
  21. System.out.println(numberOfWays(n));
  22. }
  23. }
  24.  
Success #stdin #stdout 0.1s 35376KB
stdin
50
stdout
122106097