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. int[] a = {2,3,1,4};
  14. int t1 = 1;
  15. int t2 = 5;
  16. int n = a.length;
  17. int[][] dp = new int[n+1][6];
  18.  
  19. for(int i = 0; i < n; i++){
  20. int j = i, xor1 = 0;
  21. while(j >= 0){
  22. xor1 ^= a[j];
  23. if(xor1 == t1){
  24. if(j == 0){
  25. dp[i][t1] ++;
  26. }else{
  27. dp[i][t1] += dp[j-1][t2];
  28. }
  29. }
  30. if(xor1 == t2){
  31. if(j > 0)
  32. dp[i][t2] += dp[j-1][t1];
  33. }
  34. j--;
  35. }
  36. }
  37.  
  38. System.out.print(dp[n-1][t1] + dp[n-1][t2]);
  39. }
  40. }
Success #stdin #stdout 0.09s 54584KB
stdin
Standard input is empty
stdout
1