[HUAWEI OD machine test real questions 2023B volume JAVA&JS] MELON's problem

Huawei OD2023 (B volume) machine test question bank is fully covered, click here for the guide to brushing the questions

Melon's Dilemma

Knowledge point DFS search

Time limit: 2s Space limit: 32MB Limited language: unlimited

Title description:

MELON has a pile of exquisite Yuhua stones (the number is n, with different weights), which are ready to be given to S and W. MELON hopes that the weight of the rain flower stones given to the two people will be the same. Please design a program to help MELON confirm whether the rain flower stones can be evenly distributed.

Enter a description:

The input in line 1 is the number of rain flower stones: n, 0 < n < 31.

Line 2 inputs the weight of each rain flower stone separated by spaces: m[0] m[1] ..... m[n- 1], 0 < m[k] < 1001.

There is no need to consider the case of abnormal input.

Output description:

If it can be divided equally, take at least a few pieces from the current Yuhua stone to make the weights of the two piles equal; if it cannot be divided equally, output -1.

Example 1

enter:

4
1 1 2 2

output:

2

illustrate

Guess you like

Origin blog.csdn.net/qq_34465338/article/details/131394244