TopcoderArchiveVisit Topcoder
SRM7 Dec 2016
SRM 709

Xscoregame

Problem statement, definition, constraints, and public examples.

Problem Statement

You have an array of integers: the int[] A. When you give the array to Hero, he will execute the following steps:
  1. At the beginning, he will set the variable X to zero.
  2. For each element Y of A, in the given order, he will set X to (X + (X xor Y)).
  3. He will announce the final value of the variable X.
Before you give the array A to Hero, you are allowed to permute its elements arbitrarily. Compute and return the largest possible value that can be announced by Hero.

Definition

Class:
Xscoregame
Method:
getscore
Parameters:
int[]
Returns:
int
Method signature:
int getscore(int[] A)
(be sure your method is public)

Constraints

  • A will contain between 1 and 15 elements, inclusive.
  • Each element in A will be between 0 and 50, inclusive.

Examples

  1. {1,2,3}
    Returns: 12
    An optimal solution is to rearrange A into the order {3, 1, 2}. Given this array, Hero will perform the following steps: He will set X to zero. Then, he will set X to (0 + (0 xor 3)) = 3. Then, he will set X to (3 + (3 xor 1)) = 5. Finally, he will set X to (5 + (5 xor 2)) = 12, and he will announce the value 12.
  2. {10,0,0,0}
    Returns: 80
    Here an optimal solution is to leave the array in the original order. The variable X will have the values 0, 10, 20, 40, and finally 80.
  3. {1,1,1,1,1,1}
    Returns: 1
  4. {1,0,1,0,1,0,1,0}
    Returns: 170
  5. {50,0,1,0,1,0,1,0,1,0,1,0,1,0,1}
    Returns: 830122
Back to all problems