SarthakKeshari / CPP-Questions-and-Solutions

This repository aims to solve and create new problems from different spheres of coding. A path to help students to get access to solutions and discuss their doubts.
MIT License
47 stars 132 forks source link

0-1 Knapsack Problem #386

Closed PrakharRathore123 closed 2 years ago

PrakharRathore123 commented 2 years ago

Enter your question -

Given weights and values of n items, put these items in a knapsack of capacity W to get the maximum total value in the knapsack. In other words, given two integer arrays val and wt which represent values and weights associated with n items respectively. Also given an integer W which represents knapsack capacity, find out the maximum value subset of val such that sum of the weights of this subset is smaller than or equal to W.

Test Case

Example 1)- weight array is given {15,30,40} value array is given {60,100,150} Maximum weight capacity is given = 45 so we have to input the items such the values is maximum without exceeding the weight capacity of bag. so in this the maximum value is 60+100=160 weight occcupied is 45 that doesn't exceed the Maximum weight capacity.

Example 2)- weight array is given {15,30,45} value array is given {60,100,200} Maximum weight capacity is given = 45 so we have to input the items such the values is maximum without exceeding the weight capacity of bag. so in this the maximum value is 200 weight occcupied is 45 that doesn't exceed the Maximum weight capacity.

Enter link to the question(if question belongs to any online platform) -

-

Tags for the question(eg - Array, Basic, Stack, etc.) -

Recursion , Dynamic programming ,optimization,Array

PrakharRathore123 commented 2 years ago

@SarthakKeshari Kindly issue me this problem

PrakharRathore123 commented 2 years ago

@SarthakKeshari Kindly issue me this problem

SarthakKeshari commented 2 years ago

@PrakharRathore123, Kindly add test cases to it. With input, output and explaination

PrakharRathore123 commented 2 years ago

@SarthakKeshari Kindly check the test cases

SarthakKeshari commented 2 years ago

@PrakharRathore123, Kindly add your solution to "Dynamic Programming" folder. Deadline - 10/10/2021