title: Knapsack solution with Backtraking in c++
body: <p>Im having troubles trying to resolve the Knapsack problem using backtraking.</p>
  
  <p>For example, for the following values, the Knapsack function will return 14 as the solution, but the correct result should be 7.</p>
  
  <pre><code>int n = 3, weights[] = {2, 3, 1}, values[] = {6, 15, 7};
  
  int solution = 0, max = 2;
  
  
  void Knapsack (int i, int max, int value, int *solution)
  {
    int k;
  
    for (k = i; k &lt; n; k++) {
      if (weights[k] &lt;= max) {
        Knapsack (k, max - weights[k], value + values[k], solution);
  
        if (value+ values[k] &gt; *solution) 
           *solution= value + values[k];
      }
    }
  }
  </code></pre>
  
  <p>What is the problem here?</p>