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 int solution(int n){
  11.  
  12. if(n==1 || n==2 || n==3) return 1;
  13. if(n==4) return 2;
  14. int[] dp = new int[n];
  15. dp[0] = 1;
  16. dp[1] = 1;
  17. dp[2] = 1;
  18. dp[3] = 2;
  19. for(int i=4;i<n;i++){
  20. dp[i] = (dp[i-1] % 1000000007 + dp[i-4] % 1000000007 ) % 1000000007;
  21. }
  22. return dp[n-1];
  23. }
  24. public static void main (String[] args) throws java.lang.Exception
  25. {
  26. Scanner scn = new Scanner(System.in);
  27. int n = scn.nextInt();
  28. System.out.println(solution(n));
  29. }
  30. }
Success #stdin #stdout 0.17s 56692KB
stdin
8
stdout
7