You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

JavaScript实现符合薪资限制的最优球员组合生成算法

JavaScript Solution for Optimal Team Combination (With Salary Cap)

Context & Data

First, let's lay out the core data and constraints clearly:

  • Required positions: goalkeeper, midfilder (note: this might be a typo for "midfielder", but we'll stick with the given term)
  • Player dataset (corrected to valid JSON format):
[
  {"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}
]

Requirements

We need to generate all valid team combinations that meet these rules:

  • Must include exactly one player from each of the three positions
  • Total team salary must not exceed 1100
  • Results should be sorted by total rating in descending order (higher ratings take priority)
  • Output must follow this structure (example):
[
  { "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 },
  // ... remaining valid combinations
]

Current Status

A C language implementation of this logic already exists, and we need to translate this into a working JavaScript solution.


内容的提问来源于stack exchange,提问作者Suraj

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.28 03:54:09