title: Knapsack algorithm optimized for weight instead of values
body: <p>is it possible to modify the 1-0 Knapsack algorithm to optimize the final total <strong>weight</strong> of items in the bags as first choice (and the <strong>values</strong> as second choice), maintaining the same algorithmic complexity?</p>
  
  <p>I'm working on <a href="http://java.dzone.com/articles/knapsack-problem" rel="nofollow">this java implementation</a> (in the end of the article).</p>
  
  <p>More specifically, I'm thinking of changing this piece of code </p>
  
  <pre><code>if (wt[item-1]&lt;=weight){
      V[item][weight]=Math.max (val[item-1]+V[item-1][weight-wt[item-1]], V[item-1][weight]);
  }else{
      V[item][weight]=V[item-1][weight];
  }
  </code></pre>
  
  <p>with some other condition that firstly control if the weight is closer to the threshold adding this item and than, if the weight does not change, if the value is better.</p>
  
  <p>Have you got an idea how to do this without change the complexity?</p>
  
  <p>Thank you</p>
  
  <p>EDIT
  <em>with "firstly control if the weight is closer to the threshold adding this item" i mean reaching the    weight limit of the backpack. In other words "maximizing the weight i can carry in my bag" without breaking it</em></p>