You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: notes/dynamic_programming.md
+21-7Lines changed: 21 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -292,13 +292,27 @@ We build a two-dimensional table $L[0..m][0..n]$ using the above recurrence.
292
292
293
293
#### Identifying DP Problems
294
294
295
-
* If the problem asks for the number of *ways* to do something, DP usually works because smaller counts combine into larger ones; without it, counting paths in a grid would require enumerating every route.
296
-
* If the task is to find the *minimum* or *maximum* value under constraints, DP is useful because it compares partial solutions; without it, knapsack would require checking every subset of items.
297
-
* If the same *inputs* appear again during recursion, DP saves time by storing answers; without it, Fibonacci numbers would be recomputed many times.
298
-
* If the solution depends on both the *current step* and *remaining resources* (time, weight, money, length), DP fits naturally; without it, scheduling tasks within a time limit would require brute force.
299
-
* If the problem works with *prefixes, substrings, or subsequences*, DP is often a match because these can be built step by step; without it, longest common subsequence would need exponential checking.
300
-
* If choices at each step must be explored and combined carefully, DP provides structure; without it, coin change with mixed denominations cannot guarantee the fewest coins.
301
-
* If the state space can be stored in a *table or array*, DP is feasible; without this, problems with infinitely many possibilities (like arbitrary real numbers) cannot be handled.
295
+
* If the problem asks for the number of *ways* to do something:
296
+
* Example: Counting paths in a grid.
297
+
* Consequence: Without DP, you would need to enumerate every route.
298
+
* If the task is to find the *minimum* or *maximum* value under constraints:
299
+
* Example: Knapsack problem.
300
+
* Consequence: Without DP, you would need to check every subset of items.
301
+
* If the same *inputs* appear again during recursion:
302
+
* Example: Fibonacci numbers.
303
+
* Consequence: Without DP, Fibonacci numbers would be recomputed many times.
304
+
* If the solution depends on both the *current step* and *remaining resources* (time, weight, money, length):
305
+
* Example: Scheduling tasks within a time limit.
306
+
* Consequence: Without DP, brute force would be required.
307
+
* If the problem works with *prefixes, substrings, or subsequences*:
308
+
* Example: Longest common subsequence.
309
+
* Consequence: Without DP, exponential checking would be needed.
310
+
* If choices at each step must be explored and combined carefully:
311
+
* Example: Coin change with mixed denominations.
312
+
* Consequence: Without DP, you cannot guarantee the fewest coins.
313
+
* If the state space can be stored in a *table or array*:
314
+
* Example: Problems with discrete states.
315
+
* Consequence: Without this, problems with infinitely many possibilities (like arbitrary real numbers) cannot be handled.
0 commit comments