TITLE: Why is Dantzig's solution to the knapsack problem only approximate
QUESTION [7 upvotes]: For a bunch of items with values $v_i$ and weights $w_i$, and with a total weight $W$ that our bag can carry, how do we achieve maximum total value without breaking the bag? Dantzig proposed that we consider the ratio $v_i/w_j$, and add items for which this ratio is largest until the bag fills up. But this is regarded as an approximate solution.
I have also been thinking about this problem. I came up with the same solution as Dantzig and even proved it for the $0-1$ problem. Of course, I was suspicious of my proof even before I knew the method had been proposed before (since it would imply that $P= NP$). I am even more suspicious now.
So put me out of my misery. Why doesn't it work?

REPLY [2 votes]: Just to be clear: If you fill up items according to their value/weight ratio until you cannot fit any more item in this order, the result is optimal, if the accumulated weight by then matches exactly the available space. In other words, it is ALWAYS optimal for the total weight it accumulated. I guess this is the result you had in mind. It is not hard to prove and can be found in any introduction to knapsack problems, for example in "Martello, S. & Toth, P. Knapsack problems: algorithms and computer implementations. John Wiley & Sons, 1990"
However, as discussed in the first answer and the comments there, your method obviously isn't always optimal if it ends without filling the bag completely. Think of $W=10^n$ for large $n$, and items  $A$(weight $1$, value $1$) $B$(weight $10^n$, value $10^n-1$). Then your algorithm ends up with $A$ and a value of $1$, when it could instead have had $B$ with a value of $10^n-1$. Nevertheless, $A$ is trivially optimal for the weight it achieves, i.e. optimal for a knapsack with total weight $1$.