Players Input Table The problem is making total rating maximum , while buying one player from each position with some price. For example 29000€. You can use 27000€ but you can't use 29001€.
Note: You can only buy one player from each positions so if there are 6 positions and each position has 10 players , count of all possibilities is 11^6
All i can see is knapsack problem but i think there should be some great solution for this problem.
I already tried knapsack algorithm but it didn't work well for bigger inputs like 11 positions and each position have 50 players to check.
int DP()
{
int price = 29000;
int positions = 3; // I tried this approach , it is unfinished though.
int players = 3;
int ratings[][] = new int[positions][players];
int prices[][] = new int[positions][prices];
int K[][][] = new int[positions][price][players];
for(int i = 0; i <= positions; i++)
{
for(int j = 0; j<=players; j++)
{
for(int w = 0; w<=price; w++)
{
if(i==0||j==0||w==0) // Base case.
K[i][j][w]=0;
else if(prices[i-1][w-1] <=w)
K[i][j][w] = max(ratings[i-1][j-1] + K[i-1][j-1][w-price[i-1][j-1]], K[i-1][j-1][w];
else
K[i][j][w] = K[i-1][j-1][w];
}
}
}
return K[positions][players][price];
}
Example Output:
Enter the amount to spend (X): 100 000
Enter the number of the positions (N): 6 //The first N position
Enter the number of the available players for each position (K): 5
// The first K players of each position
DP results:
Total ratings : 547
Total cost: 98 925
Players:
1-Gianfranco Zola
2-Jimmy Floyd Hasselbaink
3-...
4-...