Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/425.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 从团队的所有玩家中生成可能的玩家组合的算法_Javascript_Node.js_Algorithm_Backtracking - Fatal编程技术网

Javascript 从团队的所有玩家中生成可能的玩家组合的算法

Javascript 从团队的所有玩家中生成可能的玩家组合的算法,javascript,node.js,algorithm,backtracking,Javascript,Node.js,Algorithm,Backtracking,比如说我有3个位置和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"

比如说我有3个位置和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}]
现在,我需要建立所有可能的团队组合,所有3个位置,6名球员,最高评级,总预算工资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.]
我在这里找到了一些解决方案:
但它似乎是用C编写的,但似乎不可行,我需要用JAVASCRIPT编写

展示你的代码你自己试过写什么了吗?所以,这里不是为您编写整个脚本-如果您遇到特定问题,请询问,我们可以帮助调试。这听起来只是我的问题,还是这里描述的背包问题?只有八种可能性:2种选择为进球,2种选择为中场,2种选择为前锋提供2*2*2=8种可能性。而且他们都没有超出预算,因为在每个职位上选择最昂贵的球员可以得到1100英镑的总薪水。是的,这只是一种情况。我可以有数百名不同位置的球员。我正在编写代码,将很快添加到这里。