Introduction to Digit Dynamic Programming
When solving counting problems over large numerical ranges, traditional anumeration becomes inefficient due to redundant computations. Consider counting processes from 7000 to 7999, 8000 to 8999, and 9000 to 9999. These intervals share a common pattern: the lower three digits cycle from 000 to 999, with only the thousand's digit varying. This o ...
Posted on Wed, 20 May 2026 18:55:12 +0000 by cbrooks
Dynamic Programming on Increasing and Decreasing Sequences
Consider a sequence $A = (a_1, a_2, \dots, a_n)$. We want to partition $A$ into contiguous subsequences, and then arrange these subsequences to form a new sequence $f_1, f_2, \dots, f_k$. Each contiguous subsequence $f_1, \dots, f_p$ must satisfy either $f_1 \le f_2 \le \dots \le f_p$ or $f_1 \ge f_2 \ge \dots \ge f_p$. The cost associated with ...
Posted on Tue, 19 May 2026 12:41:33 +0000 by thedream
Computing Total Weight Contributions and Sequence Constraints via Combinatorics and Matrix Exponentiation
Problem D: Weighted Permutation Sum
Given a sequence of numbers, consider generating all its non-empty subsequences, constructing a permutation by repeatedly removing the last element until one remains, and summing the final remaining numbers across all such processes. The problem requires computing the total sum over all subsequences.
For anal ...
Posted on Mon, 18 May 2026 21:36:44 +0000 by fredmeyer
Algorithms from an Algorithmic Winter Training Camp
Balanced String Analysis (Simple and Extended)
Problem Statement
We need to analyze strings composed of 0, 1, and ?. The question marks can be replaced with either 0 or 1. The goal is to compute how many valid configurations result in "balanced" strings according to a specific criterion.
Simple Approach
For small lengths, a brute-forc ...
Posted on Mon, 18 May 2026 05:19:55 +0000 by dodgyJim
LeetCode 62: Unique Paths (Dynamic Programming, Combinatorics)
Problem Description
A robot is located at the top - left corner of an m x n grid (marked 'Start'). The robot can only move either down or right at any point. The goal is to reach the bottom - right corner (marked 'Finish'). We need to determine the number of unique paths possible.
Examples
Example 1:
Input: rows = 3, cols = 7
Output: 28
Exampl ...
Posted on Sat, 16 May 2026 05:47:43 +0000 by ansarka
AtCoder Regular Contest 104 Problem Solutions
Problem A: Plus Minus
Given the sum and difference of two numbers, we can easily retrieve the original values. The first number is the average of the sum and difference, while the second is half of the difference subtracted from the sum.
s, d = map(int, input().split())
print((s + d) // 2, (s - d) // 2)
Problem B: DNA Sequence
A substring is c ...
Posted on Fri, 15 May 2026 00:15:36 +0000 by ganich
Competitive Programming Problem Analysis: Diverse Algorithmic Challenges
This document presents an analysis of several competitive programming problems, outlining their descriptions, solution approaches, and specific implementation details or common pitfalls encountered. The problems cover various domains including number theory, combinatorics, geometry, and dynamic programming.
Problem 1: Minimizing Sum with Given ...
Posted on Thu, 14 May 2026 14:05:51 +0000 by cash09
Tree Coloring Problem Solution Using Fast Fourier Transform
This problem involves calculating valid colorings of a tree under certain constraints. The solution uses inclusion-exclution principle combined with polynomial multiplication via Number Theoretic Transform (NTT).
Basic Approach
We approach the problem by computing the complement: count arrangements where at least one node violates the coloring ...
Posted on Thu, 14 May 2026 08:51:57 +0000 by Kitara
Ambiguous Coordinate Generation Algorithm
Problem Analysis
Given a string containing only digits within parentheses, the task is to generate all valid coordinate pairs that could have produced the original string when punctuation was removed. The coordinates must adhere to specific formatting rules: no leading or trailing zeros in decimal components, and decimal points must be preceded ...
Posted on Wed, 13 May 2026 14:32:49 +0000 by nevynev
Lucas Theorem and Its Extended Application
Lucas Theorem
Mathematical Statement
Given prime $p$, the following congruence holds:
$$\binom{n}{m} \equiv \binom{\lfloor n/p \rfloor}{\lfloor m/p \rfloor} \cdot \binom{n \bmod p}{m \bmod p} \pmod{p}$$
Proof Foundation
Lemma 1
For prime $p$:
$$\binom{p}{k} \equiv 0 \pmod{p} \text{ when } 0 < k < p$$
The numerator contains factor $p$, mak ...
Posted on Tue, 12 May 2026 18:23:17 +0000 by Moneypenny