139. Word Break Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words. Note: The same word in the dictionary may be reused multiple times in the segmentation. You may...
Longest Monotonic Subsequence via Greedy Array Core Concept The "pseudo-monotonic stack" approach for finding longest monotonic subsequences uses a dynamic array that maintains potential candidates for optimal sequence construction. This method efficiently builds the solution in O(n log n)...
Knapsack Problems Knapsack problems represent one of the foundational dynamic programming concepts. Typically, either weight or value is represented as a dimension in the state space, with the smaller dimension usually chosen for optimization. When both weights and values are large, standard approac...
Problem Overview Luogu P1509 "Finding a Girlfriend" presents a multi-constraint 0/1 knapsack problem. Given n items, each with three attributes rmb_i (money), rp_i (reputation), and time_i (time spent), the goal is to maximize the number of selected items such that the sum of rmb_i does no...
The 0-1 knapsack problem serves as a foundational dynamic programming challenge. Given a time limit t and m herbs, each with a collection time and value, the goal is to maximize total value without exceeding the time limit. The solution uses a 2D DP table where dp[i][j] represents the maximum value...