用于生成来自所有队员的球员的可能组合的算法

时间:2018-05-16 05:49:41

标签: javascript node.js algorithm backtracking

我们说我有3个位置[goalkeeper, midfilder, striker]和6个玩家

[{"name":A, "position":goalkeeper, "salary":300, "rating" : 9},
{"name": B, "position":goalkeeper, "salary":200, "rating" : 8 },
{"name": C, "position":midfilder, "salary":400 , "rating" : 9},
{"name": D, "position":midfilder, "salary":300 , "rating" : 7},
{"name": E, "position":striker, "salary":400, "rating" : 9 },
{"name": F, "position":striker, "salary":200 ,"rating" : 7}]

现在我需要建立所有可能的球队组合,其中包括来自6名球员的所有3个位置,最高等级和我的总预算薪水1100.

输出应该是这样的

[{ "team" : [A,C,E],
    "total_salary" : 1100,
    "total_rating" : 27
  },
 { "team" : [B,C,E],
    "total_salary" : 1000,
    "total_rating" : 26
  },
  { "team" : [A,D,E],
    "total_salary" : 1000,
    "total_rating" : 25
  }.. all possible combinations. Players will be choosed based on position. there can't be 2 players with same position.]

我在这里找到了一些解决方案:combinations of players for a team in C 但它似乎在C但似乎不可行,我需要它在JAVASCRIPT。

0 个答案:

没有答案