#241. 数组分组求和:等和子集划分

    ID: 241 Type: Default 1000ms 256MiB Tried: 0 Accepted: 0 Difficulty: (None) Uploaded By: Tags>codingbatRecursion-2gesp6DFS背包DP

数组分组求和:等和子集划分

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 true if it's possible to divide the integers into two groups with equal sums; otherwise, output false.

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 22. For Sample 2, the total sum of array [2 3] is 55, 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 55.

Constraints

The time limit for each test case is 11 second, and the memory limit is 10241024 KiB.