#C13733. Equal Subset Sum Partition
Equal Subset Sum Partition
Equal Subset Sum Partition
This problem requires you to determine whether a given array of non-negative integers can be partitioned into two subsets having equal sum.
Given an array nums of n non-negative integers, your task is to decide if it is possible to split the array into two subsets such that the sum of the elements in both subsets is equal. This is a classical problem that can be solved efficiently using dynamic programming. In particular, if the total sum of the array is odd, the answer is immediately False
. Otherwise, you are asked to determine if there exists a subset with a sum equal to half of the total sum.
Note: All input will be provided via standard input and all output should be printed to standard output. Use the stdin for inputs and stdout for outputs.
inputFormat
The input consists of two lines. The first line contains a single integer n
, representing the number of elements in the array. The second line contains n
space-separated integers representing the array elements.
outputFormat
Output a single line containing either "True" if the array can be partitioned into two subsets with equal sum, or "False" otherwise.## sample
4
1 5 11 5
True
</p>