I am trying to complete a coding challenge from hackerrank.com
Shashank is a newbie to mathematics, and he is very excited after knowing that a given l of cardinality N has (2N - 1) non-empty sublist. He writes down all the non-empty sublists for a given set A. For each sublist, he calculates sublist_sum, which is the sum of elements and denotes them by S1, S2, S3, ... , S(2N-1).
He then defines a special_sum, P.
P = 2S1 + 2S2 + 2S3 .... + 2S(2N-1) and reports P % (10^9 + 7).
OUPUT Print special_sum, P modulo (10^9 + 7).
I am near certain I have misunderstood the prompt, but my program is meant to receive a list of numbers. The program will raise 2 to the power of all combinations of this list (without duplicates, order doesn't matter, of all sizes), then sum them all together and print it.
The example from the website is
List
1, 1, 2
Ouput44
Explanation
- {1} and 2^1 = 2
- {1} and 2^1 = 2
- {2} and 2^2 = 4
- {1,1} and 2^2 = 4
- {1,2} and 2^3 = 8
- {1,2} and 2^3 = 8
- {1,1,2} and 2^4 = 16
So the total will be 44;
My understanding of merely summing the exponents together is wrong because the answer is much larger than the expected answer in the first test case (obviously).
Input
422 412 417 497 284
Output 67920854
Essentially, I want someone to explain the prompt. I think I'm just calculating the partial sum, but I don't know when or what I'm suppose to mod 10^9 + 7
.
FYI I've only completed Algebra II, so if I've missed a mathematical concept, then keep my experience in mind when you explain it to me. I've been programming in C++, so code examples in the language is preferred.
Code My pitiful attempt at a solution: http://pastebin.com/c7YxCLMt