fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. /* Name of the class has to be "Main" only if the class is public. */
  8. class Ideone
  9. {
  10. public static void main (String[] args) throws java.lang.Exception
  11. {
  12. // your code goes here
  13. Scanner sc = new Scanner(System.in);
  14. int N = sc.nextInt();
  15. System.out.print(climbstairs(N));
  16. }
  17. public static int climbstairs(int N){
  18. int[] arr = new int[N+1];
  19. arr[1] = 1;
  20. arr[2] = 2;
  21. arr[3] = 4;
  22. for(int i=4;i<N+1;i++){
  23. arr[N] = arr[N-1]+arr[N-2]+arr[N-3];
  24. }
  25. return arr[arr.length-1];
  26. }
  27. }
Success #stdin #stdout 0.16s 54688KB
stdin
4
stdout
7