Dynamic Programming Solutions for Subsequence Problems: Longest Increasing Subsequence, Longest Continuous Increasing Subsequence, and Longest Common Subarray
Longest Increasing Subsequence (LIS)
Problem: Given an unsorted array, find the length of the longest increasing subsequence.
Dynamic Programming Approach:
Define DP array: Let lis[i] represent the length of the longest increasing subsequence ending at index i.
Transition: For each i, iterate through all j < i, and if nums[i] > nums[j], ...
Posted on Sun, 21 Jun 2026 16:25:59 +0000 by cryp7
Understanding the Core Principles of Dynamic Programming
Dynamic programming (DP) is an optimization paradigm that solves complex problems by decomposing them into overlapping subproblems whose solutions are cached to avoid recomputation. It relies on two key properties: optimal substructure and overlapping subprobelms. Optimal substructure means an optimal solution can be built from optimal solution ...
Posted on Wed, 10 Jun 2026 17:41:35 +0000 by aircooled57
Solving Problems ABC 269 (A-G)
A: Basic Arithmetic and Output
Given integers a, b, c, d, compute (a + b) * (c - d) and output the result followed by the string "Takahashi".
int a = input(), b = input(), c = input(), d = input();
cout << (a + b) * (c - d) << endl;
cout << "Takahashi" << endl;
Time complexity: O(1)
B: Finding Corne ...
Posted on Wed, 10 Jun 2026 16:36:46 +0000 by Elephant
Minimum Money for Guaranteed Win in Guessing Game
Problem Description We're playing a number guessing game with the following rules:
I pick a number between 1 and n.
You guess which number I picked.
Each time you guess wrong, I tell you whether my number is higher or lower.
When you guess a number x and it's wrong, you pay $x.
You win when you guess the correct number. Given n ≥ 1, determine ...
Posted on Tue, 09 Jun 2026 16:59:45 +0000 by void
Advanced Dynamic Programming: Interval, Tree, and Bitmask Strategies
Maximizing Collected Value from Falling Objects
Given n falling objects on a 2D plane, each with a falling speed and initial height, starting from position (x0, 0). When directly aligned with an object, it can be collected instantly, yielding a value equal to its current height divided by 1000. The objective is to maximize the total collected v ...
Posted on Tue, 09 Jun 2026 16:25:06 +0000 by KEFE
Maximizing Final Score in a Custom Jeopardy Game with Doubling Questions
In this problem, there are n questions with given point values and m special questions that allow doubling the current score instead of earning their base points. The goal is to arrange the order of answering all questions so that the final score is maximized.
Each question i has a fixed value val[i]. Among them, m indices correspond to doublin ...
Posted on Mon, 08 Jun 2026 16:10:56 +0000 by lorddraco98
Efficient Algorithms for GCD Pair Counting, Incremental Construction, and Circular Coloring
Counting GCD Pairs in Dynamic Multisets
Maintain a multiset of positive integers with insertion and deletion operations. For each query, count unordered pairs (i, j) where i ≠ j and gcd(i, j) = k.
Constraints: n, V ≤ 10^5.
Conisder the change in answer count:
$$\sum_{i=1}^{V}c_i[\gcd(i,x)=k]$$
Let x' = x/k:
$$\sum_{i=1}^{\lfloor V/k \rfloor}c_{ ...
Posted on Sat, 06 Jun 2026 17:32:00 +0000 by dhruvasagar
Binary Search and Memoized DFS for Optimization Problems
Maximizing Minimum Distance Between ElementsGiven an array of unique positions and a number of items to place, the goal is to position the items such that the minimum absolute difference between any two items' positions is maximized.Example 1:Input: positions = [1,2,3,4,7], items = 3Output: 3Explanation: Placing items at positions 1, 4, and 7 y ...
Posted on Thu, 04 Jun 2026 16:01:15 +0000 by cash09
Finding Shortest Paths with Alternating Edge Colors in Directed Graphs
Given a directed graph with nodes labeled 0 through n-1, where edge are colored either red or blue and may include self-loops and parallel edges.
Each [i, j] pair in red_edges represents a red directed edge from node i to node j. Similarly, each [i, j] pair in blue_edges represents a blue directed edge from node i to node j.
Compute an array re ...
Posted on Wed, 03 Jun 2026 17:06:15 +0000 by sharyn
Maximum Sum Divisible by Three
Given an integer array nums, find and return the maximum sum of elements that is divisible by three.
Examples
Example 1:
Input: nums = [3,6,5,1,8]
Output: 18
Explanation: Choose numbers 3, 6, 1, and 8. Their sum is 18 (the maximum sum divisible by three).
Example 2:
Input: nums = [4]
Output: 0
Explanation: 4 is not divisible by 3, so no number ...
Posted on Tue, 02 Jun 2026 17:22:57 +0000 by JamesThePanda