Partition Equal Subset Sum

MediumDynamic Programming
Next
Dynamic ProgrammingSubset SumKnapsack

Decide whether an array of positive integers can be split into two groups whose sums are equal.

Input

Line 1: n. Line 2: n positive integers.

Output

Print true if such a split exists, otherwise false.

Constraints

1 <= n <= 100 1 <= each value <= 100

Example 1
Input
4
1 5 11 5
Output
true

The groups [1, 5, 5] and [11] both sum to 11.

Example 2
Input
4
1 2 3 5
Output
false

The total 11 is odd, so no split exists.

Hints

Partition Equal Subset Sum - Medium Dynamic Programming Problem | Skill Shiksha