LeetCode 392: Is Subsequence Problem Description Given two strings s and t, determine if s is a subsequence of t. A subsequence is a sequence that can be derived from another sequence by deleting some or no characters without changing the order of the remaining characters. Dynamic Programming Soluti...
Sexagenary Cycle Offset Calculation Converting between Chinese sexagenary cycle notation and absolute year values involves identifying positions with in the 60-year cycle. The cycle combines ten celestial stems with twelve terrestrial branches. Given a target designation composed of one stem and one...
Dynamic programming (DP) is an algorithmic technique for solving problems that exhibit overlapping subproblems and optimal substructure. Overlapping subproblems mean the same smaller instances are solved repeatedly, while optimal substructure implies that an optimal solution to the larger problem ca...
Multi-Dimensional Knapsack Given N items and a knapsack with two constraints: maximum volume capacity V and maximum weight limit M. Each item i has volume c[i], weight w[i], and value v[i]. Find the maximum total value achievable without exceeding either constraint. Unlike basic knapsack problems th...
Problem Overview Consider a linear arrangement of n sequential zones, each containing a key with a specific value. The objective is to recursively divide the entire sequence until only single zones remain. During the merging phase of these divided sections, a score is accumulated. Specifically, when...
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...
Problem Statement Given a string containing only digits, count the number of ways to decode it into letters, where '1' maps to 'A', '2' maps to 'B', ..., '26' maps to 'Z'. A valid single digit must be between '1' and '9', while a valid pair must form a number between 10 and 26. State Definition Defi...
Problems that ask for a maximum or minimum sum along a path in a 2D grid can often be solved with dynamic programming where each cell’s optimal value depends on the best values of its predecessors. The recurrence follows a common pattern: best(r, c) = candidate(r, c) + max/min(best(prev1), best(prev...
Maximizing Triples Product Given three integers, you can increment any of them exactly five times. The goal is to maximize their final product. To achieve the maximum product, we should always increment the smallest of the three integers. This minimizes the disparity between the values, which yields...
In standard 0/1 knapsack problems, the objective is often to determine the number of ways to fill a specific capacity by adding items. However, challlenges arise when we need to compute the number of valid combinations after excluding a specific item from an already calculated set. Let $F[j]$ repres...