MAIN72 - Subset sum

You are given an array of N integers. Now you want to find the sum of all those integers which can be expressed as the sum of at least one subset of the given array.

Input

First line contains T the number of test case. then T test cases follow, first line of each test case contains N (1 <= N <= 100) the number of integers, next line contains N integers, each of them is between 0 and 1000 (inclusive).  

Output

For each test case print the answer in a new line.

Example

Input:
2
2
0 1
3
2 3 2

Output:
1
21

Added by:Mahesh Chandra Sharma
Date:2011-03-13
Time limit:1s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:Own problem used for NSIT-IIITA main contest #7

hide comments
2015-04-17 13:46:04 Mensud Beèar
šaša :)
2015-03-29 07:50:19 Anchrondite
Why using map gave me three TLE?While array done it in single shot.
2015-01-14 20:26:08 .::Austin::.
took a lot of time, but finally AC at 1st go :)
2014-09-01 19:35:48 Richa Jain
recurr+memo --> TLE
Bottom-up -->AC
Declare the array as static
my 50th :)
2014-08-10 23:24:27 shantanu
Sigsegv on spoj. running fine on ideone. help?

Last edit: 2014-08-11 17:08:05
2014-06-04 00:24:13 Muhammad Rifayat Samee (Sanzee)
@chayan ghosh : you can use Dynamic Programming :). you can find the solution in O(N*S) where S is the summation of all the array elements. which actually is the highest possible subset sum that can be achieved.
2013-09-12 08:54:50 Kousik Kumar
Brilliant problem! So deceiving :)
2011-12-20 17:52:34 Bharath Reddy
@ :D : Thanks

Last edit: 2011-12-21 03:03:04
2011-11-13 21:18:48 Phil Darnowsky
Looks like you mean the sum of all _proper_ subsets.
2011-10-12 17:50:12 Phong
is there any tricky in this problem? i got WA many times ...
© Spoj.com. All Rights Reserved. Spoj uses Sphere Engine™ © by Sphere Research Labs.