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, 1, 6, 3, 5};
  14. int X = 7;
  15. int n = A.length;
  16.  
  17. int[][] dp = new int[n][2];
  18.  
  19.  
  20. for(int i = 1; i < n; i++){
  21. dp[i][0] = Math.max((A[i] ^ A[i-1]) + dp[i - 1][0], (A[i] ^ (A[i-1] + X)) + dp[i - 1][1]);
  22. dp[i][1] = Math.max(((A[i] + X) ^ (A[i-1] + X)) + dp[i-1][1], ((A[i] + X) ^ (A[i-1])) + dp[i-1][0]);
  23. }
  24. System.out.print( Math.max(dp[n-1][0], dp[n-1][1]));
  25. }
  26. }
Success #stdin #stdout 0.07s 52548KB
stdin
Standard input is empty
stdout
51