Guest User

Untitled

a guest
Jan 23rd, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.05 KB | None | 0 0
  1. ACM International Collegiate Programming Contest, Asia-Amritapuri Site, 2011
  2. Problem D: Sub-sequences
  3. Having discovered that the Muggle-born* students of Hogwarts School of Witchcraft & Wizardry are all on Facebook, Headmaster Dumbledore decided to go with the flow and has hired an ICPC World Finalist to teach all the students about this 'compooter-thingy' and how to program it to do its 'automatic spells'. Harry is struggling with his latest homework assignment, which is as follows:
  4.  
  5. You are given a sequence of N numbers A[1..N]. Consider a sub-sequence** such that the bitwise AND of all the numbers of the sub-sequence is equal to the bitwise OR of all the numbers of the sub-sequence. Amongst all such sub-sequences, find the sub-sequence that has the maximum sum of the numbers, and print this maximum sum.
  6.  
  7. Can you help Harry finish his homework before he chews through all his writing quills in frustration?
  8.  
  9. *Muggle-born: Magical children born of non-magical parents.
  10. Input (STDIN):
  11. The first line contains the number of test cases T. T cases follow. Each test case consists of N in the first line followed by N space-separated integers on the next line denoting the values A[1..N].
  12. Output (STDOUT):
  13. Output T lines, one for each case containing the required answer(maximum sum as explained in the problem) for the corresponding case.
  14. Constraints:
  15. 1 <= T <= 20
  16. 1 <= N <= 10000
  17. 0 <= A[i] <= 10000
  18. Time limit: 3 seconds
  19. Sample Input:
  20. 2
  21. 3
  22. 1 2 3
  23. 2
  24. 1 1
  25. Sample Output:
  26. 3
  27. 2
  28. Notes:
  29. **A sub-sequence is a sequence that can be derived from another sequence by deleting 0 or more elements without changing the order of the remaining elements.
  30.  
  31. A bitwise AND of two integers is the logical AND operation on each pair of corresponding bits in the binary representation of the two integers.
  32. For example,
  33. 0101 (decimal 5)
  34. AND 0011 (decimal 3)
  35. = 0001 (decimal 1)
  36. The bitwise OR operation is the logical AND operation on each pair of corresponding bits in the binary representation of the two integers.
  37. 0101 (decimal 5)
  38. OR 0011 (decimal 3)
  39. = 0111 (decimal 7)
Add Comment
Please, Sign In to add comment