Fantasy premier league dream team algorithm?
You can formulate an integer program for this problem. For each player $i$ let $a_i$ be the number of points the player scored, $p_i$ is his price. Moreover, let $G, B, M, F$ be the set of goal keepers, backs, midfielders and forwards, respectively, $P := G \cup B \cup M \cup F$ the set of all players, and $C$ is the salary cap. We use binary variables $x_i \in \{0, 1\}$ for each player $i$, were $x_i = 1$ iff player $i$ is in the optimal roster, $0$ otherwise. The optimal roster is then induced by the solution of the following program:
$$\begin{aligned}
\text{maximize } &amp; \sum_{i \in P} a_i x_i\\
\text{subject to } &amp; \sum_{i \in P} p_i x_i \leq C\\
&amp; \sum_{i \in G} x_i = 1\\
&amp; \sum_{i \in B} x_i = 4\\
&amp; \sum_{i \in M} x_i = 4\\
&amp; \sum_{i \in F} x_i = 2\\
&amp; x_i \in \{0, 1\} &amp; i \in P
\end{aligned}
$$
Now you may have noticed that the objective function + capacity constraint is indeed a knapsack problem but you have additional constraints on the formation.

Although you can use a MIP solver of your choice, you might even exploit this knapsack structure as a subproblem by using a knapsack solver (I think there is some very popular dynamic programming approach).