I have a list of players and each player has a salary and a rating (both integer values).
I have to find n-th largest combination of 6 players (largest in terms of sum of their ratings) with a constraint that the sum of their salaries must be less or equal than 50000.
For example, if I have a list of players 1,2,...,m, what I'm currently doing is:
This is obviously a brute force approach which works fine for smaller number of players. But currently I have 140 players which yield over 9 billion combinations and it takes too much to finish.
Any suggestion on how to do this faster?
Here is how you can avoid getting all the combinations.
This will get your ranks sorted on descending order and the first key in the map will be the highest rank. If you have multiple records having the same rank, consider putting them as a list against the same rank.
Here if you have more than one record against a rank, try adding their salaries as well.
This will take some patience and some good testing to translate to a program, but will certainly be an optimal solution.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.