πŸ“’ Too many exams? Don’t know which one suits you best? Book Your Free Expert πŸ‘‰ call Now!

  • google app store apple app store
  • βœ–

      Question

      In a 0/1 Knapsack problem implemented using dynamic programming, a common mistake is to allow items to be reused, effectively turning it into an unbounded knapsack. Which part of the recurrence relation, if incorrectly formulated, would lead to this bug?

      A dp[i][j] = max(dp[i-1][j], dp[i-1][j - weights[i]] + values[i]) Correct Answer Incorrect Answer
      B dp[i][j] = max(dp[i-1][j], dp[i][j - weights[i]] + values[i]) Correct Answer Incorrect Answer
      C dp[i][j] = dp[i-1][j] Correct Answer Incorrect Answer
      D dp[i][j] = dp[i][j - weights[i]] + values[i] Correct Answer Incorrect Answer
      E dp[i][j] = values[i] Correct Answer Incorrect Answer

      Solution

      The correct answer is B

      Practice Next
      ask-question