- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

Suppose we have a list A. We have taken all non-empty sublists of A as we know a list l with n elements has (2n - 1) non-empty sublist. Now for each sublist, he calculates sublist_sum (the sum of elements and denotes them by S_{1}, S_{2}, S_{3}, ... , S_{(2N-1)}). There is a special sum P such that P = 2^{S1} + 2^{S2} +2^{S3} .... + 2^{S(2N-1)}. We have to find P. If P is too large then return P mod (10^9 + 7).

So, if the input is like A = [2,2,3], then the output will be The subsets are

- {2} so 2^2 = 4
- {2} so 2^2 = 4
- {3} so 2^3 = 8
- {2,2} so 2^4 = 16
- {2,3} so 2^5 = 32
- {2,3} so 2^5 = 32
- {2,2,3} so 2^7 = 128

Sum is 4 + 4 + 8 + 16 + 32 + 32 + 128 = 224

To solve this, we will follow these steps −

- ans:= 1
- m:= 10^9+7
- for each el in A, do
- ans := ans *(1 + (2^el mod m))
- ans := ans mod m

- return (m + ans-1) mod m

Let us see the following implementation to get better understanding −

def solve(A): ans=1 m=10**9+7 for el in A: ans *= (1+pow(2,el,m)) ans %= m return (m+ans-1) % m A = [2,2,3] print(solve(A))

[2,2,3]

224

- Related Questions & Answers
- Program to find range sum of sorted subarray sums using Python
- Program to find the sum of all digits of given number in Python
- Program to find sum of the sum of all contiguous sublists in Python
- Python Program to find the sum of array
- Find the sum of array in Python Program
- Find the sum of maximum difference possible from all subset of a given array in Python
- C/C++ Program to Find sum of Series with n-th term as n power of 2 - (n-1) power of 2
- Program to find maximum absolute sum of any subarray in Python
- Program to find out the value of a power of 2 in Python
- Program to find sum of all elements of a tree in Python
- Program to find Reordered Power of 2 in Python
- Program to find sum of beauty of all substrings in Python
- Program to find total sum of all substrings of a number given as string in Python
- Program to find out the sum of the maximum subarray after a operation in Python
- Python program to find the sum of all items in a dictionary

Advertisements