Skip to content

Commit e01d082

Browse files
authored
Create About Algorithm
1 parent 2ceac8c commit e01d082

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
0/1 Knapsack Problem using Dynamic Programming Approach
2+
3+
0/1 Knapsack Problem
4+
5+
- We are given N items where each item has some weight and profit associated with it.
6+
- We are also given a bag with capacity W, [i.e., the bag can hold at most W weight in it].
7+
- The target is to put the items into the bag such that the sum of profits associated with them is the maximum possible.
8+
9+
Note: The constraint here is we can either put an item completely into the bag or cannot put it at all [It is not possible to put a part of an item into the bag].
10+
11+
Examples:-
12+
13+
Input: N = 3, W = 4, profit[] = {1, 2, 3}, weight[] = {4, 5, 1}
14+
15+
Output: 3
16+
17+
Explanation: There are two items which have weight less than or equal to 4. If we select the item with weight 4, the possible profit is 1.
18+
And if we select the item with weight 1, the possible profit is 3. So the maximum possible profit is 3. Note that we cannot put both the items with weight 4 and 1 together as the capacity of the bag is 4.
19+
20+
Input: N = 3, W = 3, profit[] = {1, 2, 3}, weight[] = {4, 5, 6}
21+
Output: 0

0 commit comments

Comments
 (0)