算法-在不使用重复元素的情况下,找到结果为K的最大和数

时间:2019-05-09 09:47:26

标签: c algorithm

家庭作业问题:

编程竞赛中最明显的弱点之一是,每个类别中只有一名获胜者。这意味着很多人不敢参加或半途而废地看到别人比他更好。解决此问题的方法是为鼓励团队合作的团体赢得冠军,从而使一个以上的人选择奖品。

即使如此,我们也是一样:如果有一支非常优秀的团队,那肯定会赢,而其他团队则不想参加。但是我们已经找到了可以在第三届比赛中实施的这一障碍的解决方案:我们将成为组织比赛的组织者。

形成小组的方式有些特殊,但我们仍在寻找最佳方法。目前,我们对此感到满意:

Once all participants are registered, we will order them alphabetically.
Each participant has their level of expertise. This value has been chosen by him / her and indicates how capable it is to solve programming problems.
The groups will be made from one or more consecutive members from the list (remember that we have ordered them).
Each participant can be part of a single team.
At the time of making the groups we will look at the level of expertise of its members, we want teams to be balanced! More formally: each group must have the same level of total expertise, where the total level of expertise of a team is the sum of the expertise of each one of its members.
We would like to train as many teams as possible with the same number of total expertise (we want to have many teams and all of them balanced!).
There may be participants who are left without a group. But well, do not worry we have a whole year to find out how we will solve this little drawback.
In case you have more than one solution, that is, more than one way of forming the maximum number of balanced groups, we will remain with that configuration that generates a higher level of total expertise in each group.

如果我们要优先考虑的是让(平衡的)组参加比赛的人数最多,那么组的总专业水平是多少?

如果我们使具有相同总专业知识水平的连续成员组成的小组,我们有很多选择,例如:

With total expertise 1, we could do two teams: {4, 1, 2, 2, 1, 5, 3}. (1,1)
With total expertise 2, we could do two teams: {4, 1, 2, 2, 1, 5, 3}. (2,2)
With total expertise 3, we could do three teams: {4, 1, 2, 2, 1, 5, 3}. (1,2)(2,1)(3)
With total expertise 4, we could do two teams: {4, 1, 2, 2, 1, 5}.(4)(2,2)
With total expertise 5, we could do three teams: {4, 1, 2, 2, 1, 5, 3}. (4,1)(2,2,1)(5)
And so we could do other combinations with different levels of expertise.

很明显,没有分组是完美的,不幸的是,会有一些参与者没有分组。另外请注意,可能只有一个人的小组。

为了使比赛更加有趣,我们的目标是使尽可能多的小组参加。因此,在这种情况下,我们可以选择3级或5级专业知识,这两种技能都可以使我们组建3个团队。在这种情况下,我们选择总的专业知识5级,因为它高于3级。

在第二个测试中,我们可以组成3个团队,总专业水平为2级。

在第三次测试中,我们可以组成4个总技能等级为1的团队。

在第四项测试中,我们只能为每个级别的总专业知识建立一个团队:

With total expertise 1: {8, 4, 2, **1**}: a group
With total expertise 2: {8, 4, **2**, 1}: a group
With total expertise 3: {8, 4,**2**, **1**}: a group
With total expertise 4: {8, **4**, 2, 1}: a group
With total expertise 8: {**8**, 4, 2, 1}: a group
...

没有办法产生给我们一个以上均衡团队的团队。这将是一个无聊的比赛,但完全有效而公平。在一个小组中,拥有最高专业知识的小组是15:{ 8 4 2 1 }

我该如何推销该算法?

0 个答案:

没有答案