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