• Courses
  • Tutorials
  • DSA
  • Data Science
  • Web Tech
August 25, 2024 |460 Views

PROBLEM OF THE DAY : 24/08/2024 | 0 - 1 Knapsack Problem

Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Nitin Kaplas We will discuss the entire problem step-by-step and work towards developing an optimized solution. This will not only help you brush up on your concepts of Dynamic Programming but also build up problem-solving skills.

You are given weights and values of items, and put these items in a knapsack of capacity W to get the maximum total value in the knapsack. Note that we have only one quantity of each item.
In other words, given two integer arrays val and wt which represent values and weights associated with items respectively. Also given an integer W which represents knapsack capacity, find out the maximum sum values subset of val[] such that the sum of the weights of the corresponding subset is smaller than or equal to W. You cannot break an item, either pick the complete item or don't pick it (0-1 property).

Examples :

Input: W = 4, val[] = {1,2,3}, wt[] = {4,5,1} Output: 3
Explanation: Choose the last item that weighs 1 unit and holds a value of 3. 

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1