Problem 193
Partition Equal Subset Sum
Medium · 20 pts · Array, Dynamic Programming
Problem
You are given an array of N positive integers. Decide whether it can be split into two groups with equal sums, where every element goes into exactly one of the two groups. If the total is odd, it is impossible. Otherwise you need a subset that sums to exactly half the total. Use a subset-sum table: reachable[s] says whether some subset sums to s, and each number x updates reachable[s] |= reachable[s - x] for s going down from the target to x.
Input
First line: integer N. Second line: N space-separated integers.
Output
Print YES or NO.
Constraints
1 <= N <= 200; 1 <= A[i] <= 100
Example input
4 1 5 11 5
Example output
YES
Explanation
The array 1 5 11 5 has total 22, so each group must sum to 11. The groups {1, 5, 5} and {11} both sum to 11, so the answer is YES.