本文介绍了如何划分数字组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

A =(a1,a2,.. aN} - n个元素的集合 - (正整数)必须分成K个子集,以便每个子集中所有元素的总和等于m =(a1 + a2 + .. + a)/ K.

算法必须为A计算所有这些情况。如果不可能分组,程序生成不可能



例如:

A = {a1,a2,a3,a4} = {5,4,6,5}

K = 2

m =(5 + 4 + 6 + 5)/ 2 = 10

分组:{(5,5),(4,6)},5 + 5 = 4 + 6



输入:

5 4 6 5

2

输出:

1





感谢帮助

Bkac

A=(a1, a2,.. aN}- set of n numbers elements- (positive integers) must be divided into K subsets in order to sums of all elements in each subset were equal to m=(a1+a2+..+an)/K.
Algorithm must count ALL such cases for A. If it’s impossible to divided set A program generates „IMPOSSIBLE"

for example:
A={a1,a2,a3,a4}={5,4,6,5}
K=2
m=(5+4+6+5)/2=10
Divided set: {(5,5),(4,6)}, 5+5=4+6

Input:
5 4 6 5
2
Output:
1


Thanks for HELP
Bkac

推荐答案


这篇关于如何划分数字组的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 08:58