Curated sets

Dynamic programming ladder

Every judgeable DP problem, easiest first.

All problems
Total results3,128 problems
TopicsJudge
The nth Fibonacci NumberGiven n up to 20, compute the nth Fibonacci number defined from 0 and 1.Easy1Dynamic programmingRecursionNo attempts yet1s256 MBJudgeable
Fibonacci Number 2Compute the nth Fibonacci number for n up to 90.Easy2Dynamic programmingMathNo attempts yet1s128 MBJudgeable
Fibonacci-like SequenceGiven n up to 116, compute the n-th term of the recurrence f(n) = f(n-1) + f(n-3) with f(1)=f(2)=f(3)=1.Easy2Dynamic programmingMath+1No attempts yet2s512 MBJudgeable
RGB StreetGiven per-house costs for three colors, compute the minimum total cost to paint all houses in a line so that no two adjacent houses share a color.Easy3Dynamic programmingArrayNo attempts yet0.5s128 MBJudgeable
Make It OneCompute the minimum number of divide-by-3, divide-by-2, or subtract-1 operations needed to reduce N to 1.Easy3Dynamic programmingMathNo attempts yet0.15s128 MBJudgeable
GreetingGiven health costs and joy values for up to 20 people, pick a subset maximizing total joy while keeping total health loss below 100.Easy3Dynamic programmingNo attempts yet2s128 MBJudgeable
01 TilesCount length-N binary strings tileable by '1' and '00' pieces, modulo 15746, which reduces to a Fibonacci recurrence.Easy3Dynamic programmingMathNo attempts yet0.75s256 MBJudgeable
Maximum Subarray SumGiven up to 100,000 integers, compute the maximum sum of a non-empty contiguous subarray.Easy3Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Integer TriangleGiven a triangle of up to 500 rows, compute the maximum sum path from top to bottom moving diagonally at each step.Easy3Dynamic programmingMatrixNo attempts yet2s128 MBJudgeable
OvertakingGiven entry and exit orders of N cars, count how many cars are not part of the longest common subsequence, meaning they overtook someone.Easy3Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Downward GameGiven an N x 3 grid with limited column transitions between rows, compute the maximum and minimum total path sums from top to bottom.Easy3Dynamic programmingMatrixNo attempts yet1s4 MBJudgeable
Pinary NumbersCount binary strings of length N that start with 1 and have no two consecutive 1s, using Fibonacci-style counting with big integers up to N=90.Easy3Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Sum DecompositionCount ordered sequences of K integers from 0 to N whose sum equals N, modulo 1,000,000,000.Easy3Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Minimum Coin CountGiven n coin denominations, compute the minimum number of coins (unlimited supply) that sum to exactly k, or -1 if impossible.Easy3Dynamic programmingNo attempts yet1s128 MBJudgeable
CombinationGiven n and m within 100, compute the exact value of the binomial coefficient C(n, m).Easy3MathCombinatorics+1No attempts yet2s128 MBJudgeable
SequenceFind the maximum length of a contiguous subarray of digits that is either nondecreasing or nonincreasing.Easy3ArrayDynamic programming+1No attempts yet1s128 MBJudgeable
Line UpFind the minimum number of children to move so the line ends in sorted order, equivalent to N minus the longest increasing subsequence length.Easy3Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Apartment ResidentsCompute the resident count in room n on floor k, defined by repeated prefix sums starting from room i having i residents on floor 0.Easy3Dynamic programmingMath+1No attempts yet0.5s128 MBJudgeable
Keypad PasswordsCount length-N digit sequences on a phone keypad where consecutive digits must be adjacent keys, modulo 1,234,567, for up to N=1000.Easy3Dynamic programmingGraph+1No attempts yet1s128 MBJudgeable
Counting Coin CombinationsCount the number of ways to sum a set of coin denominations (unlimited use, order ignored) to reach a target amount, for multiple test cases.Easy3Dynamic programmingNo attempts yet1s128 MBJudgeable
DollarsSimulate converting between dollars and marks daily using given rates to maximize final dollar amount, truncated to two decimals.Easy3GreedySimulation+1No attempts yet1s128 MBJudgeable
Towers of CoinsGiven move options 1, K, or L coins in a Nim-like turn game, determine for each pile size whether the first player wins under optimal play.Easy3Dynamic programmingGame theoryNo attempts yet1s128 MBJudgeable
ProfitGiven a sequence of daily profits, find the maximum total over any non-empty stretch of consecutive days, across several test cases.Easy3ArrayDynamic programming+1No attempts yet1s256 MBJudgeable
Fibonacci NumberGiven n, print the n-th Fibonacci number, where the sequence starts 1, 1 and each later term is the sum of the previous two.Easy3Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Exact ChangeGiven a price and a multiset of up to 100 coin values, pick a subset summing to at least the price; minimize the sum first, then the number of coins.Easy3Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
SkylineWe have N trapezoidal buildings listed from nearest to farthest. For each building, we must compute the fraction of its area that remains visible, i.e., the part of the trapezoid not hidden by any closer building. The presence of overlapping sloped roofs makes the computation nontrivial: for a given building we need to determine, for each horizontal coordinate, the maximum roof height among all closer buildings. Then the visible area is the integral, over the building’s own range [x1, x2], of the positive part of the difference between the building's top edge (roof) and that maximum height.ForEasy3GeometryIntervals+2No attempts yet1s128 MBJudgeable
Toxic AssetsGiven current values of basic investments and acyclic derivative definitions, compute the current worth of a portfolio made of these investments.Easy3Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Coin RowGiven rows of coin values, pick non-adjacent coins to maximize the total collected in each row.Easy3Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Commute RouteCount monotone east/north lattice paths from (1,1) to (a,b) that avoid n blocked intersections, with a and b at most 16.Easy3Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
ProfitsGiven a sequence of N daily profits, find the maximum sum over any contiguous stretch of days.Easy3ArrayDynamic programming+2No attempts yet1s128 MBJudgeable
Eating TogetherGiven a sequence of values from 1 to 3, find the fewest card changes so the sequence becomes non-decreasing or non-increasing.Easy3ImplementationBrute force+1No attempts yet1s128 MBJudgeable
World Cup NoiseFor each n below 45, count the n-bit strings that contain no two adjacent 1s, and print the result per scenario with a blank line between cases.Easy3Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Making ChangeGiven a target amount and up to 10 coin denominations, find the fewest coins that sum exactly to the target.Easy3Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Four QuartersFor each round count from 1 to 20, compute the probability that A wins, B wins, or the game ties after that many rounds of this four-coin game.Easy3ProbabilityDynamic programming+1No attempts yet1s128 MBJudgeable
Mouse JourneyCount monotone right/down paths on an R by C grid from (1,1) to (R,C) that avoid K blocked cat cells.Easy3Dynamic programmingMatrix+1No attempts yet2s512 MBJudgeable
ElevatorRusnė goes from floor 0 to floor N using the elevator for at most K segments; minimize the total height of the segments she climbs on foot.Easy3GreedySorting+1No attempts yet1s1024 MBJudgeable
Prehistoric Operating SystemsCount binary strings of length n with no two adjacent D's, where D means DOORS and O means any other brand, for up to 40 test values of n.Easy3Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Board GameStarting on field 1, move forward 1 to 6 fields per step to reach field n while collecting the largest possible sum of visited values.Easy3Dynamic programmingNo attempts yet1s128 MBJudgeable
The Score ChartGiven a sequence of 0s, 1s, and 2s, find the length of the longest subsequence that never decreases.Easy3Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
EncodingCount binary strings of length n that start with 1 and contain no adjacent ones for up to 100 queries.Easy3Dynamic programmingCombinatoricsNo attempts yet1s128 MBJudgeable
Adding 1, 2, and 3Count the ordered ways to write n as a sum of 1, 2, and 3 for each test case with n below 11.Easy3Dynamic programmingNo attempts yet1s512 MBJudgeable
Function run funCompute the recursive function w(a, b, c) with memoization for each query line until -1 -1 -1.Easy3Dynamic programmingRecursionNo attempts yet1s128 MBJudgeable
Taxi RoutesCount the routes from the southwest to the northeast corner of a grid up to 30 by 30 that move only east or north and avoid blocked intersections.Easy3Dynamic programmingMatrixNo attempts yet1s128 MBJudgeable
FundraisedChoose unlimited units of N item kinds within budget X to maximize total importance.Easy3Dynamic programmingNo attempts yet1s128 MBJudgeable
Padovan SequenceFor each test case, compute the Nth Padovan number defined by the spiral of equilateral triangles.Easy3Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Generations of TribblesCompute the nth term of a four-term Fibonacci-like recurrence for up to 68 test cases with precomputation.Easy3Dynamic programmingNo attempts yet2s128 MBJudgeable
Equal Sum SetsCount subsets of {1..n} with exactly k elements that sum to s for each dataset.Easy3Dynamic programmingCombinatoricsNo attempts yet3s128 MBJudgeable
BABBAStarting from A and rewriting each B as BA and each A as B, count the As and Bs after K presses.Easy3Dynamic programmingMathNo attempts yet1s128 MBJudgeable
Stone GameTwo players alternately take 1 or 3 stones from a pile of N, and the program names the winner under perfect play.Easy3Dynamic programmingGame theoryNo attempts yet1s128 MBJudgeable
Stone Game 2Two players alternately take 1 or 3 stones from a pile of N and the player taking the last stone loses, so print whether the first player wins.Easy3Game theoryDynamic programmingNo attempts yet1s128 MBJudgeable
Stone Game 3Two players alternately take 1, 3, or 4 stones from a pile of N, and the program reports whether the first player wins with perfect play.Easy3Dynamic programmingGame theoryNo attempts yet1s128 MBJudgeable
Stone Game 4Two players alternately take 1, 3, or 4 stones and the player taking the last stone loses; report whether the first player wins with optimal play.Easy3Dynamic programmingGame theoryNo attempts yet1s128 MBJudgeable
Stone Game 6Two players alternately take 1, 3, or 4 stones from a pile of N, and the program prints which player wins with perfect play.Easy3Game theoryDynamic programmingNo attempts yet1s128 MBJudgeable
Two Mysterious Alphabets from a TreeFind the max-sum root-to-leaf path in a number triangle, breaking ties by larger sum of squares, then print both sums and their mod-26 letters.Easy3Dynamic programmingNo attempts yet1s128 MBJudgeable
Best Machine Rental ProfitEach record maps letters to profits, and the task asks for the largest sum over any contiguous block, or zero when every block loses money.Easy3Dynamic programmingArrayNo attempts yet2s512 MBJudgeable
GeckoPick a top-row tile and move straight down, down-left, or down-right each row to maximize the mosquitoes eaten.Easy3Dynamic programmingMatrixNo attempts yet2s512 MBJudgeable
Grid Path CountCount right-and-down paths from the top-left to the bottom-right corner that pass through a given cell, if one is specified.Easy3CombinatoricsDynamic programmingNo attempts yet1s256 MBJudgeable
Maximum Subarray SumFor each test case, find the maximum sum over all contiguous subarrays of the given integer array.Easy3Dynamic programmingArrayNo attempts yet1s256 MBJudgeable
Tigger's bouncesCount length-K walks on an R by C grid where each step stays put or moves to a side neighbor, summed over all starts, modulo P per query.Easy3Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Maximal SumFind the contiguous block of edge weights with the largest sum and print its endpoints, or print no good path when the best sum is not positive.Easy3Dynamic programmingArrayNo attempts yet1s64 MBJudgeable
Valid Parenthesis CountCount the distinct correct parenthesis strings of length L for each test case, modulo 1000000007.Easy3CombinatoricsDynamic programming+1No attempts yet2s256 MBJudgeable
A Population of RabbitsCount rabbit pairs alive in month M given lifespan D and breeding ages up to R, starting from one newborn pair.Easy3Dynamic programmingSimulationNo attempts yet1s256 MBJudgeable
COWCount the subsequences equal to COW in a string of C, O, and W up to length 100000.Easy3Dynamic programmingStringNo attempts yet1s256 MBJudgeable
Fibonacci Numbers 4Compute the nth Fibonacci number for n up to 10000 using arbitrary-precision arithmetic.Easy3Dynamic programmingImplementationNo attempts yet1s256 MBJudgeable
Stair Number CountCount length-N numbers with no leading zero where adjacent digits differ by 1, modulo 1,000,000,000.Easy3Dynamic programmingNo attempts yet1s256 MBJudgeable
MovingJungyu collects the most candy possible walking from the top-left room to the bottom-right room with right, down, and diagonal moves.Easy3Dynamic programmingMatrixNo attempts yet1s256 MBJudgeable
Binomial Coefficient 2Compute the binomial coefficient C(N, K) modulo 10007 for N up to 1000.Easy3Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Buying cardsGiven pack prices P_1 to P_N, choose packs whose card counts sum to exactly N to maximize the total price.Easy3Dynamic programmingNo attempts yet1s256 MBJudgeable
Largest Sum Increasing SubsequencePick elements in order so each is larger than the last and their sum is as large as possible.Easy3Dynamic programmingArrayNo attempts yet1s256 MBJudgeable
Ascending NumbersCount length-N digit strings, leading zeros allowed, whose digits never decrease left to right, modulo 10007.Easy3Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
LOLFind the fewest insertions, replacements, and deletions that make each given word contain lol as a contiguous substring.Easy3Dynamic programmingStringNo attempts yet1s256 MBJudgeable
Neurotic NetworkEvaluate the weighted sum from the leaves to the root of a tree and print FREAK OUT for an even result, else the value modulo 1,000,000,007.Easy3TreeDynamic programming+1No attempts yet1s256 MBJudgeable
Hunger GamesChoose weapons within the sack weight limit to maximize total preference.Easy3Dynamic programmingNo attempts yet3s256 MBJudgeable
PIN Code PossibilitiesCount n-digit codes with leading zeros allowed whose digits add up to s for each test case.Easy3Dynamic programmingCombinatoricsNo attempts yet3s256 MBJudgeable
Safe ZoneCount the K-step walks on segments 0 to N-1 with forced turns at the ends that finish inside segments P to Q.Easy3Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Path FindingDecide for every ordered pair of vertices in a directed graph with up to 100 vertices whether a path of at least one edge connects them.Easy3GraphDynamic programmingNo attempts yet1s256 MBJudgeable
Compositions Missing a SequenceCount the ordered compositions of n that use no part from the arithmetic progression starting at m with step k.Easy3Dynamic programmingCombinatoricsNo attempts yet1s256 MBJudgeable
Longest Decreasing SubsequenceFind the length of the longest strictly decreasing subsequence of the given sequence.Easy3Dynamic programmingNo attempts yet1s256 MBJudgeable
2 by n TilingCount the ways to tile a 2 by n rectangle with 1 by 2 dominoes and print the count modulo 10007.Easy3Dynamic programmingNo attempts yet1s256 MBJudgeable
2 by n Tiling 2Count the ways to tile a 2 by n rectangle with dominoes and 2 by 2 squares, modulo 10007.Easy3Dynamic programmingNo attempts yet1s256 MBJudgeable
Squawk VirusStarting from user s, propagate squawk counts along links for t minutes and report how many squawks are sent at time t.Easy3Dynamic programmingGraphNo attempts yet1s256 MBJudgeable
Array EscapeFind the cheapest right-and-down path through a square grid where stepping to a higher or equal neighbor costs the raises needed to exceed it.Easy3Dynamic programmingShortest path+1No attempts yet2s256 MBJudgeable
Polynesiaglot (Small 1)Count length-L words over C consonants and V vowels in which each consonant is directly followed by a vowel, modulo 1000000007.Easy3Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
PolynesiaglotCount length-L strings over C consonants and V vowels with no adjacent consonants and no trailing consonant, modulo 1e9+7.Easy3Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
Polynesiaglot (Large)Count length-L words over C consonants and V vowels where every consonant is followed by a vowel, modulo 1e9+7.Easy3Dynamic programmingCombinatoricsNo attempts yet5s512 MBJudgeable
Sums of 1, 2, 3 (2)Find the k-th composition of n using parts 1, 2 and 3 in lexicographic order, or print -1 when it does not exist.Easy3BacktrackingDynamic programmingNo attempts yet1s512 MBJudgeable
Ordinary KnapsackGiven N items with weights and values, pick a subset with total weight at most K to maximize total value.Easy3Dynamic programmingNo attempts yet2s512 MBJudgeable
Recurrence sequenceCompute the n-th term of a self-convolution recurrence where t(n) sums t(i)*t(n-1-i) for i from 0 to n-1, with n up to 35.Easy3Dynamic programmingMath+2No attempts yet5s512 MBJudgeable
Splitting the Pizza Tower (Small)A tower of N pizzas is repeatedly split into two smaller towers, each split scoring the product of the two new heights. Find the maximum total score (N ≤ 10).Easy3Dynamic programmingMath+1No attempts yet1s512 MBJudgeable
What's Your Tier?Starting at 2000 points, play 20 games with given win, loss, and draw probabilities; compute the probability of ending in each of five tiers.Easy3ProbabilityDynamic programming+2No attempts yet2s256 MBJudgeable
Assigning roomsGiven three distinct room capacities and a student count, decide whether some nonnegative combination of the capacities sums exactly to the count.Easy3Dynamic programmingMath+2No attempts yet2s512 MBJudgeable
CrammingGiven N chapters, each with a study time and a score, choose a subset whose total study time fits in T to maximize the total score.Easy3Dynamic programmingArray+2No attempts yet2s256 MBJudgeable
Falling ApartGiven up to 15 positive integers, two players alternately take one piece; find the final sums under optimal play.Easy3Dynamic programmingGame theory+1No attempts yet2s512 MBJudgeable
Going Down 2Given N rows of three digits, move down choosing reachable cells and report the maximum and minimum possible sum of the digits passed through.Easy3Dynamic programmingArrayNo attempts yet1s512 MBJudgeable
Virus OutbreakRead hour values until -1 and print the Fibonacci number a(X) for each in the format 'Hour X: Y cow(s) affected'.Easy3MathDynamic programming+2No attempts yet2s512 MBJudgeable
PotionGiven market prices and mixture recipes, compute the cheapest cost to produce one unit of the potion named LOVE.Medium4GraphDynamic programming+2No attempts yet2s128 MBJudgeable
ZooCount the ways to place non-attacking lions in a 2 by N grid so that no two lions sit in adjacent cells, modulo 9901.Medium4Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Infinite SequenceCompute the N-th term of a sequence where A_i equals A at floor(i/P) plus A at floor(i/Q), using memoized recursion for huge N.Medium4RecursionDynamic programming+2No attempts yet2s128 MBJudgeable
Tournament WinnerGiven all pairwise win probabilities among 8 players in a fixed single-elimination bracket, compute each player's probability of winning the whole tournament.Medium4ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Highway ShortcutsCompute the minimum driving distance from position 0 to D on a highway with up to 12 one-way shortcuts that skip forward sections.Medium4Shortest pathGraph+2No attempts yet2s128 MBJudgeable