#241. 数组分组求和:等和子集划分
数组分组求和:等和子集划分
Array Group Sum
Background
Congcong is playing a number game.
Problem Description
Given an array of integers, is it possible to divide the integers into two groups such that the sums of the two groups are the same? Every integer must be in one group or the other. Write a recursive helper method that takes whatever arguments you like, and make the initial call to your recursive helper from splitArray(). (No loops needed.)
Input Format
Input is given from Standard Input in the following format.
The input consists of a single line representing an array of integers. The elements of the array are separated by spaces.
Output Format
Output is printed to Standard Output in the following format.
Output
trueif it's possible to divide the integers into two groups with equal sums; otherwise, outputfalse.
Sample
[2 2]
true
[2 3]
false
[5 2 3]
true
Sample Explanation
For Sample 1, the array [2 2] can be divided into two groups: {2} and {2}, both with a sum of .
For Sample 2, the total sum of array [2 3] is , which cannot be divided into two groups with equal sums.
For Sample 3, the array [5 2 3] can be divided into two groups: {5} and {2, 3}, both with a sum of .
Constraints
The time limit for each test case is second, and the memory limit is KiB.