Here size(S) = ∑a∈ S size(a) and profit(S) = ∑a∈ S profit(a).
The problem is NP-complete. On the other hand, there is an algorithm that works in time polynomial in n and P, where P is the maximum item profit. It uses dynamic programming.
To see how, start with the observation that the maximum total profit is surely bounded by nP.
Define A(i,p) to be the minimum size of any subset with total profit p using just the first i items.
Then A(i,p) satisfies the following recurrence:
Fix ε > 0.
We want a solution of profit at least OPT - ε OPT.
Note that the maximum obtainable profit is at least P.
Thus, it suffices to find a solution of profit at least OPT - ε P.
Consider rounding each profit profit(a) down to the nearest multiple of δ = ε P / n.
That is, profit'(a) = δ ⌊ profit(a) / δ⌋.
This decreases the profit of any item by at most δ, and so decreases the profit of any set of items by at most nδ = ε P.
Thus, the optimal solution to the modified problem will approximate the optimal solution to the original problem within 1-ε factor. (Exercise.)
Thus, it suffices to find an optimal solution to the modified problem.
In the modified problem, every profit is a multiple of δ, and the profits are between 0 and P.
If we further modify the problem by multiplying each profit by 1/δ, we get an equivalent problem where the profits are integers between 0 and P/δ = n/ε.
We can solve this problem optimally using the first algorithm we discussed. The optimal set of items for this problem gives us a solution to the original problem whose size is at most C and whose profit is within a 1-ε factor of optimal.
thm: For any ε>0, there exists a (1-ε)-approximation algorithm that runs in time polynomial in n and ε.
Note that this means we can approximate the problem to any desired degree of accuracy.
We can think of the algorithm a single algorithm that takes ε as input, or we can think of it as a family of algorithms, one for each ε, and each running in time polynomial in n (with the constant depending on ε. This is called a polynomial-time approximation scheme, or PTAS.
Because the dependence of the running time on 1/ε is polynomial, this is also called a fully polynomial-time approximation scheme, or FPTAS.