Possible Sums
Practice
3.9 (25 votes)
Algorithms
Approved
Dynamic programming
Medium
Open
Two dimensional
Problem
26% Success 4558 Attempts 30 Points 3s Time Limit 256MB Memory 1024 KB Max Code

Given an array A of N elements, find the number of distinct possible sums that can be obtained by taking any number of elements from the array and adding them.

Note that 0 can always be obtained by taking none.

First line of the input contains number of test cases T. Each test case has two lines. First line has N, the number of elements in the array followed by N values which are elements of the array. For each test case, print a single line, the distinct possible sums that can be obtained.

Constraints
1 <= T <= 10
1 <= N <= 100
0 <= A[i] <= 100 for 0 <= i < N

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
23 votes
Tags:
AlgorithmsApprovedDynamic ProgrammingMediumOpenTwo dimensional
Points:30
58 votes
Tags:
ApprovedDynamic ProgrammingGraphsMathMediumOpenRecursionTwo dimensional
Points:30
54 votes
Tags:
2D dynamic programmingAlgorithmsDynamic ProgrammingMediumPermutation and combination