HUAWEI OD Machine Test-Maximum Bisected Array-2022Q4 Volume A-Py/Java/JS

Given an array nums, the elements can be divided into several groups, so that the sum of each group is equal, and the maximum number of equal groups among all groups that meet the conditions is found.

Input description:
Enter m in the first line
and then enter m numbers to represent this array
Data range: 1<=M<=50, 1<=nums[i]<=50

Output description:

The maximum number of parallel groups.

Example 1:

enter:

7
4 3 2 3 5 2 1

output:

4

Explanation: The situations that can be equally divided are:

4 subsets (5), (1,4), (2,3), (2,3)

2 subsets (5, 1, 4), (2,3, 2,3)

The maximum number of flat groups is 4.

Example 2:

enter:

9
5 2 1 5 2 1 5 2 1

output:

4

Explanation: The situations that can be equally divided are:

4 subsets (5,1), (5,1), (5,1), (2,2,2)

2 subsets (5, 1, 5,1), (2,2, 2,5,1)

The maximum number of flat groups is 4.
 

java code

<

Guess you like

Origin blog.csdn.net/miao_9/article/details/130235555