Skip to content

Commit c742922

Browse files
committed
update DP
1 parent 89337d7 commit c742922

File tree

1 file changed

+61
-15
lines changed

1 file changed

+61
-15
lines changed

✅ Pattern 15: 0-1 Knapsack (Dynamic Programming).md

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -118,14 +118,21 @@ Let’s apply this knowledge to solve some of the frequently asked <b>DP</b> pro
118118

119119
# Pattern 1: 0/1 Knapsack
120120
<b>Problem Set</b>
121+
121122
[🔎 0/1 Knapsack](#🔎-01-knapsack-medium)
123+
122124
[Equal Subset Sum Partition](#equal-subset-sum-partition-medium)
125+
123126
[Subset Sum](#🔎-subset-sum-medium)
127+
124128
[Minimum Subset Sum Difference ](#minimum-subset-sum-difference-hard)
129+
125130
[🌟Count of Subset Sum](#🌟count-of-subset-sum-hard)
131+
126132
[🌟 Target Sum](#🌟-target-sum-hard)
127133

128134

135+
129136
<b>0/1 Knapsack pattern</b> is based on the famous problem with the same name which is efficiently solved using <b>Dynamic Programming (DP)</b>.
130137

131138
In this pattern, we will go through a set of problems to develop an understanding of <b>DP</b>. We will always start with a brute-force recursive solution to see the overlapping subproblems, i.e., realizing that we are solving the same problems repeatedly.
@@ -1544,14 +1551,23 @@ console.log(
15441551

15451552
# Pattern 2: Unbounded Knapsack
15461553
<b>Problem Set</b>
1554+
1555+
[Unbounded Knapsack](#unbounded-knapsack)
1556+
1557+
[Rod Cutting](#rod-cutting)
1558+
1559+
[🔎👩🏽‍🦯 Coin Change](#🔎👩🏽‍🦯-coin-change)
1560+
1561+
[Minimum Coin Change](#minimum-coin-change)
1562+
1563+
[Maximum Ribbon Cut](#maximum-ribbon-cut)
1564+
15471565
[]()
1566+
15481567
[]()
1568+
15491569
[]()
1550-
[]()
1551-
[]()
1552-
[]()
1553-
[]()
1554-
[]()
1570+
15551571
##
15561572

15571573
> Given the weights and profits of `N` items, we are asked to put these items in a knapsack with a capacity `C`. The goal is to get the `maximum profit` out of the knapsack items. The only difference between the <b>[0/1 Knapsack pattern](#pattern-1-01-knapsack)</b> problem and this problem is that we are allowed to use an unlimited quantity of an item.
@@ -2348,6 +2364,10 @@ https://leetcode.com/problems/cutting-ribbons/
23482364

23492365
We are given a ribbon of length `n` and a set of possible `ribbonLengths`. We need to cut the ribbon into the maximum number of pieces that comply with the above-mentioned possible lengths. Write a method that will return the count of pieces.
23502366

2367+
> Given a number array to represent possible `ribbonLengths` and a total ribbon length `n`, we need to find the maximum number of pieces that the ribbon can be cut into.
2368+
2369+
This problem follows the <b>[Unbounded Knapsack pattern](#pattern-2-unbounded-knapsack)</b> and is quite similar to <b>[Minimum Coin Change (MCC)](#minimum-coin-change)</b>. The only difference is that in <b>[Minimum Coin Change (MCC)](#minimum-coin-change)</b>, we were asked to find the <b>minimum</b> number of coin changes, whereas, in this problem, we need to find the <b>maximum</b> number of pieces.
2370+
23512371
#### Example 1:
23522372

23532373
```
@@ -2374,10 +2394,6 @@ Ribbon Lengths: {3,5,7}
23742394
Output: 3
23752395
Explanation: Ribbon pieces will be {3,3,7}.
23762396
```
2377-
##
2378-
> Given a number array to represent possible `ribbonLengths` and a total ribbon length `n`, we need to find the maximum number of pieces that the ribbon can be cut into.
2379-
2380-
This problem follows the <b>[Unbounded Knapsack pattern](#pattern-2-unbounded-knapsack)</b> and is quite similar to <b>[Minimum Coin Change (MCC)](#minimum-coin-change)</b>. The only difference is that in <b>[Minimum Coin Change (MCC)](#minimum-coin-change)</b>, we were asked to find the <b>minimum</b> number of coin changes, whereas, in this problem, we need to find the <b>maximum</b> number of pieces.
23812397

23822398
### Basic Brute Force Solution
23832399

@@ -2505,15 +2521,24 @@ console.log(
25052521
25062522
# Pattern 3: Fibonacci Numbers
25072523
<b>Problem Set</b>
2524+
2525+
[Fibonacci numbers](#fibonacci-numbers)
2526+
2527+
[🔎👩🏽‍🦯 Staircase](#🔎👩🏽‍🦯-staircase)
2528+
2529+
[Number factors](#number-factors)
2530+
2531+
[🌴 Minimum jumps to reach the end](#🌴-minimum-jumps-to-reach-the-end)
2532+
2533+
[Minimum jumps with fee](#minimum-jumps-with-fee)
2534+
2535+
[🌴 🔎 👩🏽‍🦯 House thief](#🌴-🔎-👩🏽‍🦯-house-thief)
2536+
25082537
[]()
2509-
[]()
2510-
[]()
2511-
[]()
2512-
[]()
2513-
[]()
2514-
[]()
2538+
25152539
[]()
25162540
2541+
25172542
## Fibonacci numbers
25182543
https://leetcode.com/problems/fibonacci-number/
25192544
@@ -3283,12 +3308,19 @@ We can clearly see that this problem follows the <b>[Fibonacci number pattern](#
32833308
32843309
# Pattern 4: Palindromic Subsequence
32853310
<b>Problem Set</b>
3311+
32863312
[Longest Palindromic Subsequence](#longest-palindromic-subsequence)
3313+
32873314
[👩🏽‍🦯 🌴 Longest Palindromic Substring](#👩🏽‍🦯-🌴-longest-palindromic-substring)
3315+
32883316
[👩🏽‍🦯 Count of Palindromic Substrings](#👩🏽‍🦯-count-of-palindromic-substrings)
3317+
32893318
[🔎 Minimum Deletions in a String to make it a Palindrome](#🔎-minimum-deletions-in-a-string-to-make-it-a-palindrome)
3319+
32903320
[Minimum insertions in a string to make it a palindrome](#1-minimum-insertions-in-a-string-to-make-it-a-palindrome)
3321+
32913322
[Find if a string is K-Palindromic](#2-find-if-a-string-is-k-palindromic)
3323+
32923324
[Palindromic Partitioning](#palindromic-partitioning)
32933325
32943326
## Longest Palindromic Subsequence
@@ -4222,20 +4254,34 @@ console.log(`Minimum palindrome partitions ---> ${findMPPCuts('madam')}`);
42224254
42234255
# Pattern 5: Longest Common Substring
42244256
### Problem Set
4257+
42254258
[Longest Common Substring](#longest-common-substring)
4259+
42264260
[🔎 Longest Common Subsequence](#🔎-longest-common-subsequence)
4261+
42274262
[Minimum Deletions & Insertions to Transform a String into another](#minimum-deletions--insertions-to-transform-a-string-into-another)
4263+
42284264
[👩🏽‍🦯 🔎 Longest Increasing Subsequence](#👩🏽‍🦯-🔎-longest-increasing-subsequence)
4265+
42294266
[Maximum Sum Increasing Subsequence](#maximum-sum-increasing-subsequence)
4267+
42304268
[Shortest Common Super-sequence](#shortest-common-super-sequence)
4269+
42314270
[Minimum Deletions to Make a Sequence Sorted](#minimum-deletions-to-make-a-sequence-sorted)
4271+
42324272
[Longest Repeating Subsequence](#longest-repeating-subsequence)
4273+
42334274
[Subsequence Pattern Matching](#subsequence-pattern-matching)
4275+
42344276
[Longest Bitonic Subsequence](#longest-bitonic-subsequence)
4277+
42354278
[Longest Alternating Subsequence](#longest-alternating-subsequence)
4279+
42364280
[🔎 Edit Distance](#🔎-edit-distance)
4281+
42374282
[🔎 Strings Interleaving](#🔎-strings-interleaving)
42384283
4284+
42394285
## Longest Common Substring
42404286
https://www.geeksforgeeks.org/longest-common-substring-dp-29/
42414287
> Given two strings `str1` and `str2`, find the length of the longest <b>substring</b> which is common in both the strings.

0 commit comments

Comments
 (0)