5

0 – 1 Knapsack Problem

 9 months ago
source link: https://www.geeksforgeeks.org/videos/0-1-knapsack-problem-1/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

0 – 1 Knapsack Problem

August 17, 2023 |40 Views
0 – 1 Knapsack Problem
SDE Sheet, GFG SDE Sheet, dynamic-programming
 Save  Share  1 Like
Description
Discussion

This video is part of the Dynamic Programming section in the GFG SDE Sheet.

In this video, we are 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. Note that we have only one quantity of each item.
In other words, given two integer arrays val[0..N-1] and wt[0..N-1] 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. You cannot break an item, either pick the complete item or dont pick it (0-1 property).

Example :

Input:
N = 3
W = 4
values[] = {1,2,3}
weight[] = {4,5,1}
Output: 3

Try it out before watching the implementation of the problem in the video. We recommend watching the video, even if you can solve the problem. You may discover something new. All the best!!!

Do check out:-

Article: https://www.geeksforgeeks.org/0-1-knapsack-problem-dp-10/
Problem: https://practice.geeksforgeeks.org/problems/0-1-knapsack-problem0945/1
SDE Sheet: https://www.geeksforgeeks.org/sde-sheet-a-complete-guide-for-sde-preparation/

Read More

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK