Algorithmic Problem Solving Techniques and Implementations
Equalizing Card Piles (Greedy Approach)
To distribute cards equally among $N$ piles, calculate the average number of cards per pile and subtract this value from each pile's count. This transforms the problem into finding the minimum number of moves to zero out the differences. Iterating from left to right, if a pile has a non-zero discrpeancy, ...
Posted on Wed, 10 Jun 2026 16:32:25 +0000 by bdichiara
Optimization and Strategy Problems on Sequences and Grids
Resource Redistribution with Asymmetric Operations
Given a sequence (a) of length (n) and two positive integers (x, y) where (y \le x). You may repeatedly pick two elements and transfer resources: subtract (x) from one and add (y) to the other, provided the first remains non‑negative. Determine the maximum possible value of any element after op ...
Posted on Tue, 09 Jun 2026 17:33:25 +0000 by obesechicken13
Comprehensive Guide to Dynamic Programming Patterns and Implementations
Minimum Path Sum in a Grid
Finding the minimum path sum from the top-left to the bottom-right of a grid is a classic dynamic programming problem. To optimize space complexity, we can use a 1D array instead of a 2D matrix to store the DP states, updating the array iteratively as we traverse each row.
#include <vector>
#include <algorith ...
Posted on Thu, 04 Jun 2026 17:28:26 +0000 by m4tt
SMU Summer 2024 Contest Round 4 - Problem Editorials
Made Up
Problem Statement Given three sequences A, B, C, count the number of pairs (i, j) such that A[i] = B[C[j]].
Solution Approach Since all values are bounded between 1 and N, we can use frequency counting. For each value v, count how many times it appears in array A (stored in cntA) and how many times it appears as B[C[j]] (stored in cntB) ...
Posted on Thu, 04 Jun 2026 16:57:11 +0000 by reyes99
Sliding Window and Spiral Matrix Algorithms
Problem Description
Given an array of n positive integers and a positive integer target, find the length of the shortest continuous subarray whose sum is at least target. Return the length of this subarray. If no such subarray exists, return 0.
Example 1:
Input: target = 7, nums = [2,3,1,2,4,3]
Output: 2
Explanation: The subarray [4,3] has the ...
Posted on Thu, 04 Jun 2026 16:09:14 +0000 by 8mycsh
Graph Theory: Multi-source and Single-source Shortest Path Algorithms
Shortest path problems in graph theory often rely on the concept of relaxation. Relaxation occurs when a path from node u to v can be shoretned by routing through an intermediate node k, i.e., if dist[u][v] > dist[u][k] + dist[k][v], we update dist[u][v] accordingly.
Floyd-Warshall Algorithm (All-Pairs Shortest Paths)
To compute shortest pat ...
Posted on Wed, 03 Jun 2026 18:20:34 +0000 by little_tris
Algorithm Solutions: Path Search, String Ranking, and Knapsack Problems
D - Path Traversal
A straightforward depth-first search approach can solve this traversal problem.
int nodes, edges, max_steps, min_cost, max_cost;
vector<int> valid_endpoints;
vector<pair<int, int>> graph[MAX_NODES];
void traverse(int current_node, int current_cost, int steps_taken) {
if (current_cost > max_cost) retu ...
Posted on Fri, 29 May 2026 19:58:58 +0000 by volant
2012 NOIP Popularization Group Finals Walkthrough
Task 1 – Factor Splitting
Given a positive integer n that is the product of two distinct primes, output the larger one.
Input: One integer n (≤ 2·109).
Output: The larger prime factor.
Observation: The first divisor (other than 1) must be the smaller prime, so the answer is n / i once the smallest i > 1 with n % i == 0 is found.
#include < ...
Posted on Thu, 28 May 2026 22:28:35 +0000 by dannyd
Dynamic Programming Fundamentals and Applications
Linear DP
Core Concepts
Dynamic Programming (DP) solves complex problems by breaking them in to overlapping subproblems. The solution to the main problem is derived from solutions to these subproblems.
State Representation
State are typically represented as dp[i][j] = value, where i and j are indices or variables describing the state, and value ...
Posted on Thu, 28 May 2026 20:03:56 +0000 by d3ad1ysp0rk
Solving Sequential Placement Problems with Overlapping Constraints via Linear Dynamic Programming
The problem models a sequential arrangement where each position $i$ offers two distinct categories of elements. Category X occupies exactly one slot, while Category Y spans two consecutive slots $(i-1, i)$. The objective is to compute the total number of valid configurations modulo $10^9+7$.
A two-state dynamic programming approach efficiently ...
Posted on Thu, 28 May 2026 18:09:44 +0000 by scorphus