• Courses
  • Tutorials
  • Jobs
  • Practice
  • Contests
October 26, 2023 |1.4K Views
PROBLEM OF THE DAY: 25/10/2023 | Knapsack with Duplicate Items
Description
Discussion

Welcome to the daily solving of our PROBLEM OF THE DAY with Karan Mashru. 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 will also help you build up problem-solving skills.

In this problem, we are given, a set of N items, each with a weight and a value, represented by the array w and val respectively. Also, a knapsack with weight limit W.
The task is to fill the knapsack in such a way that we can get the maximum profit. Return the maximum profit.
Note: Each item can be taken any number of times.

Example :

Input: 
N = 2
W = 3
val = {1, 1}
wt = {2, 1}
Output: 
3

Explanation: 
1.Pick the 2nd element thrice.
2.Total profit = 1 + 1 + 1 = 3. Also the total weight = 1 + 1 + 1  = 3 which is <= 3.

Give the problem a try before going through the video. All the best!!!
Problem Link: https://practice.geeksforgeeks.org/problems/knapsack-with-duplicate-items4201/1
Solution IDE Link: https://ide.geeksforgeeks.org/online-cpp-compiler/d59b72bf-cdf8-4415-8163-ae8f845a5567