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 #398

Closed PrakharRathore123 closed 2 years ago

PrakharRathore123 commented 2 years ago

Issue Id you have worked upon -

386

Briefly explain your program logic -

1)Initialize the value and weight array 2)If weight of bag is less than equal to zero the return zero 3)If No. of items is less than equal to zero the return zero 4)If weight of last items is more than weight of bag then return for n-1 item 5)Their is two possibility take or not if take it then item are 1 minus and weight is weight minus weight of that item + val of that item else item number is one less

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.

Screenshots(Attach 2 screenshots of your own input and output) -

Attach here KNAPSACKA KNAPSACKB


Checklist:

Eg - If your code follow the below guidelines. Kindly change [] to [x]

All the conditions should be fulfilled for considering your code for merging -

PrakharRathore123 commented 2 years ago

@SarthakKeshari Kindly acknowledge this.

Abhi-1301 commented 2 years ago

Please assign me this i can contribute to it

SarthakKeshari commented 2 years ago

Please assign me this i can contribute to it

@Abhi-1301 This is a PR. Kindly claim issues. You may refer CONTRIBUTING.md for further details.