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. int arr[]=new int[n];
  16. for(int i=0;i<n;i++) arr[i]=sc.nextInt();
  17.  
  18. int dp[][]=new int[n+1][2];
  19. int odd=0;
  20. int even=1;
  21. if(arr[0]%2==0)dp[1][even]=1;
  22. else dp[1][odd]=1;
  23.  
  24. for(int i=2;i<=n;i++){
  25. if(arr[i-1]%2==0){
  26. dp[i][odd]=dp[i-1][odd]+dp[i-2][odd];
  27. dp[i][even]=dp[i-1][even]+dp[i-2][even];
  28. }else{
  29. dp[i][odd]=dp[i-1][even]+dp[i-2][even];
  30. dp[i][even]=dp[i-1][odd]+dp[i-2][odd];
  31. }
  32. }
  33. System.out.println("Odd sum journies: "+dp[n-1][odd]);
  34. System.out.println("Even sum journies: "+dp[n-1][even]);
  35. }
  36. }
Success #stdin #stdout 0.13s 58860KB
stdin
5
2 3 5 8 10
stdout
Odd sum journies: 2
Even sum journies: 1