3 of 3 replaced http://cs.stackexchange.com/ with https://cs.stackexchange.com/

If you want to solve this in practice, I would suggest that you formulate it as an instance of integer linear programming (ILP).

You can have a variable $x_i$ for each article that is one if we buy the $i$th article, or $0$ otherwise. Now you get some constraints. For instance, if I want 2 of the Dreadlord card, and they're offered in the 3rd, 7th, and 8th articles, then I get the constraint that $x_3+x_7+x_8 \ge 2$. The objective function is your total cost. You want to minimize your total cost, subject to the requirements.

Here's how you can model the total cost. The only tricky bit are the shipping costs. For simplicity, assume that the shipping cost from a seller is fixed no matter how many items you buy from that seller. To help with modeling the shipping costs, introduce a variable $y_j$ for each seller, where $y_j=1$ if you buy anything from the $j$th seller and $y_j=0$ otherwise. Now use the "logical OR" construction from here to relate the $y_j$'s to the $x_i$'s. For instance, suppose that articles 4, 5, and 9 are from seller 2. Then you add the linear inequalities $y_2 \ge x_4$, $y_2 \ge x_5$, $y_2 \ge x_9$, $y_2 \le x_4 + x_5 + x_9$, $0 \le y_2 \le 1$. Do this for each seller. Now, the total cost is $$\sum_i c_i x_i + \sum_j c'_j y_j,$$ where $c_i$ is the per-item cost of the card in the $i$th article and $c'_j$ is the shipping cost of the $j$th seller. This is the objective function that you're going to try to minimize.

Then, throw an off-the-shelf ILP solver at the resulting set of constraints.

This problem is likely to be NP-hard, so in principle there might not be any efficient solution... but in practice ILP solvers are surprisingly good, so I bet they'll give you a pretty good solution to your problem.


Possible complications and details: If the seller has multiple copies of a card available, we need to modify the above. You can have $x_i$ count the number of them that you buy from that seller (instead of being 0 or 1). Also, we need to modify the construction of the $y_j$'s, as follows. For instance, if article 5 is from seller 2, and article 5 offers up to 17 copies of the Dreadlord card, then instead of $y_2 \ge x_5$, you should use $17 y_2 \ge x_5$ (this ensures that if $x_5 \ge 1$, then $y_2$ is forced to be $1$).

If the shipping cost is not constant per seller, then you might need a more complex model of the cost. However, here's one simple case that you can handle without difficulty. Suppose that the shipping cost for seller 2 is \$3 plus \$0.50 per card ordered. Then you can treat this as a fixed shipping cost of \$3 (regardless of how many cards are ordered), and increase the per-item cost of each card offered by that seller by \$0.50. If the shipping cost is a non-linear function of the number of cards bought, then you might need something fancier: in that case, you might want to ask a follow-up question about how to model that specific nonlinear function, and specify the nonlinear fucntion. Or, you could approximate the shipping cost by a linear function and solve the ILP problem anyway, to get something that might be close to optimal, even if your model isn't perfect.