Curated sets

Dynamic programming ladder

Every judgeable DP problem, easiest first.

All problems
Total results3,128 problems
TopicsJudge
Letter BoardCount the number of paths on an N by M letter grid that spell a given word, moving 1 to K cells in one straight direction per step.Medium5Dynamic programmingMatrix+1No attempts yet2s128 MBJudgeable
String CopyFind the minimum number of substring-copy operations from S needed to reconstruct P using greedy/DP over matching positions.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Marbles in BoxesGiven two marble sequences and a pairwise score table, choose a sequence of pop/pop/pop-both operations to maximize total matched-pair score, using LCS-like DP with reconstruction.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Team FormationPartition an age-ordered score sequence into contiguous groups to maximize the sum of each group's max-minus-min score.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Sequence ReductionDecide if repeatedly merging adjacent elements as A[i]-A[i+1] can reduce the sequence to a single target value T.Medium5Dynamic programmingRecursionNo attempts yet2s128 MBJudgeable
Plum TreeGiven a sequence of falling trees over T seconds, find the max plums caught starting at tree 1 with at most W moves between trees.Medium5Dynamic programmingNo attempts yet2s128 MBJudgeable
JumpFind the minimum number of jumps from stone 1 to stone N where jump lengths change by at most 1 each step and some stones are blocked.Medium5Dynamic programmingBFS+1No attempts yet2s128 MBJudgeable
Theater SeatsCount permutations where each ticket holder sits in their own or adjacent seat, with VIP seats fixed and splitting the row into independent segments counted by a Fibonacci-like recurrence.Medium5Dynamic programmingCombinatorics+1No attempts yet2s128 MBJudgeable
Buying JewelsFor each of n rows pick a contiguous non-empty subarray maximizing summed total value, breaking ties by fewest jewels then lexicographically smallest index sequence.Medium5Dynamic programmingArray+1No attempts yet2s128 MBJudgeable
Tree CuttingGiven a tree with n vertices, find the minimum number of edges to cut so some resulting piece has exactly m vertices, or report impossibility.Medium5TreeDynamic programming+1No attempts yet2s128 MBJudgeable
Fax CompressionChoose a quantization of a sequence into 4 levels with run-length style bit encoding to minimize error plus weighted code length.Medium5Dynamic programmingString+1No attempts yet2s128 MBJudgeable
Dance Pad Minimum EnergyGiven a sequence of dance pad moves, compute the minimum total energy to press each in order by choosing which of two feet to move each time.Medium5Dynamic programmingSimulationNo attempts yet2s128 MBJudgeable
Polygon PartitionsCount noncrossing dissections of a regular N-gon into all triangles or all quadrilaterals, modulo 1e9, using Catalan-like combinatorics.Medium5CombinatoricsDynamic programming+1No attempts yet2s128 MBJudgeable
Number of PermutationsGiven a permutation's up-down pattern, count permutations of size n sharing the same pattern, modulo 1,000,000,000.Medium5Dynamic programmingCombinatoricsNo attempts yet2s128 MBJudgeable
Sum of Powers of TwoCount the ways to write N as an unordered sum of powers of two, modulo one billion.Medium5Dynamic programmingMath+1No attempts yet2s128 MBJudgeable
Brotherly Field DivisionChoose a non-decreasing staircase cut across N columns of an N x N grid to minimize the harvest difference between the two regions, and output one such cut.Medium5Dynamic programmingBrute force+1No attempts yet1s256 MBJudgeable
ParameciaSimulate a population where each individual matures, reproduces daily within an age window, dies at a fixed age, and count survivors on day N modulo 1000.Medium5Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
Electric WiresGiven wires connecting positions on two poles, find the minimum removals so remaining wires never cross, equivalent to n minus the longest increasing subsequence.Medium5Dynamic programmingBinary search+1No attempts yet1s128 MBJudgeable
Crossing the Stone BridgesCount ways to match a scroll string to positions across two parallel bridge strings, alternating bridges and strictly increasing positions.Medium5Dynamic programmingStringNo attempts yet1s128 MBJudgeable
Corporate InvestmentAllocate exactly N integer units of money across M companies using given profit tables to maximize total profit, then output an allocation, a classic knapsack-style DP task.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
Submarine IdentificationDecide whether a binary string can be split into pieces of '01' or '1' followed by at least two 0s and at least one 1, using pattern matching or DP.Medium5Dynamic programmingString matching+1No attempts yet1s128 MBJudgeable
Glass BallsGiven B balls and M floors, compute the minimum number of drops needed to guarantee finding the critical breaking floor in the worst case.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Adjacent Bit Pair CountCount binary strings of length n whose number of adjacent 11-pairs equals a given k, for up to 1000 queries.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
KnightSimulate a knight's moves on an N x N board for T steps (T up to a million), where each square can only be entered at time-multiples of its written value, and output all possible final squares.Medium5BFSSimulation+1No attempts yet1s128 MBJudgeable
Dongjun's GameGiven N level scores, find the minimum total decrease needed to make the sequence strictly increasing while all scores stay positive.Medium5GreedyArray+1No attempts yet1s128 MBJudgeable
Pleasant WordCount ways to fill blanks in a word with uppercase letters so it avoids three consecutive vowels or consonants and contains at least one 'L'.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
DebugGiven a binary R by C grid, find the largest square submatrix (side at least 2) that is invariant under 180-degree rotation, or output -1.Medium5Dynamic programmingMatrix+1No attempts yet5s128 MBJudgeable
FootnotesGiven text lines and footnotes attached to specific lines, compute the minimum number of pages so that each page holds consecutive text lines plus their footnotes within a line limit K.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Foot TypingGiven two words and their interleaving, output the lexicographically smallest sequence of 1s and 2s marking which word produced each character.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
ExchangeGiven daily buy and sell exchange rates between marks and dollars, compute the maximum marks obtainable after N days starting from 100 marks, output as a reduced fraction.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Friends Calling PlanGiven call minutes between up to 16 employees, pair them all up to minimize total billing cost using bitmask DP over perfect matchings.Medium5Dynamic programmingBit manipulation+1No attempts yet1s128 MBJudgeable
Hop, HopCount, modulo 1000000, the number of ways to write n as a non-increasing sequence of jumps of length 1, 2, or 3, for n up to 1e9.Medium5MathDynamic programming+1No attempts yet1s128 MBJudgeable
Ancient ManuscriptCount ways to fill '*' letters in a word so runs of vowels/consonants respect maximum length and maximum equal-letter-repeat limits, using DP over letter classes and previous letter identity.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Decoding Morse SequencesCount the number of ways to split a given Morse code string into a sequence of dictionary words, using dynamic programming with Morse-to-word conversion.Medium5Dynamic programmingString+1No attempts yet1s128 MBJudgeable
Sangkeun TowerFor each elevator, find the minimum floor above 0 reachable using exactly n button presses (up/down moves), never going below 0, then take the overall minimum across elevators.Medium5Dynamic programmingBrute force+1No attempts yet1s128 MBJudgeable
Graph MatchingCount the number of matchings (independent edge sets) of the cycle graph C_n for each given n, likely requiring big-integer arithmetic via a Lucas-sequence style recurrence.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
ComputersGiven a fixed replacement cost and arbitrary maintenance costs for owning a computer over any year range, find the minimum total cost to cover n years using dynamic programming.Medium5Dynamic programmingArrayNo attempts yet1s128 MBJudgeable
Game, Set and MatchGiven the per-point win probability p, compute the probabilities of winning a tennis game, set, and match using the standard scoring rules.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Minimal BackgammonSimulate turn by turn probability mass over board positions (with lose-a-turn and go-to-start squares, and bounce-back overshoot rule) to find probability of reaching the goal within T turns.Medium5Dynamic programmingSimulation+1No attempts yet1s128 MBJudgeable
Sum of Distinct PrimesCount subsets of k distinct primes summing to n, using dynamic programming over sieve-generated primes up to 1120.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
Maximum SumGiven n boxes of numbered balls, pick at most one ball per box in order to form a non-decreasing sequence with maximum possible sum.Medium5Dynamic programmingSortingNo attempts yet1s128 MBJudgeable
Faulhaber's TriangleBuild Faulhaber's triangle row by row using the recurrence F(i,j)=i/j*F(i-1,j-1) plus the normalization that each row sums to 1, then answer queries for F(m,k) as reduced fractions.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
CounterattackTwo strikers advance in lockstep through n points, each step either dribbling or passing to the partner; find the cheapest route from a long pass at point 1 to a shot at point n.Medium5Dynamic programmingArray+1No attempts yet1s256 MBJudgeable
Pro-Test VotingGiven a budget and precincts whose vote gain follows a concave spending curve, allocate dollars to maximize rounded total votes, breaking ties toward lower-numbered precincts.Medium5Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Largest SquareGiven a 0/1 matrix, find the side length of the largest all-ones square submatrix.Medium5Dynamic programmingMatrixNo attempts yet5s256 MBJudgeable
SkylineCount permutations of 1..N with no increasing subsequence of length 3, modulo 1,000,000, for each N up to 1,000.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Ferry Loading VGiven distinct vehicle weights, split them between two lanes so the totals differ as little as possible. Output the minimum difference.Medium5Dynamic programmingPrefix sum+1No attempts yet1s128 MBJudgeable
Scrolling SignGiven k-wide words, find the minimum total letters scrolled in so that each word appears in order, allowing overlap between consecutive words.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Catamaran BallastSplit the given rock weights between two hulls so the difference of the two sums is as small as possible.Medium5Dynamic programmingBrute forceNo attempts yet1s128 MBJudgeable
Multiplication GameAlice and Bob multiply a running product by 2 to 9 in turn; find who forces the product to reach n first with optimal play.Medium5Game theoryDynamic programming+1No attempts yet1s128 MBJudgeable
Tight WordsCount words of length n over digits 0..k where adjacent digits differ by at most 1, then print that count as a percentage rounded to five decimals.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Splitting Teams FairlySplit N people into two teams differing in size by at most one so their total weight difference is minimized, then print both totals in increasing order.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Old Wine Into New BottlesGiven a wine volume and bottle sizes with min and max capacities, maximize the bottled amount and print the leftover in millilitres.Medium5Dynamic programmingGreedy+1No attempts yet1s128 MBJudgeable
Ferry LoadingLoad the longest prefix of cars onto two lanes of bounded total length, choosing lanes to maximize cars loaded and break ties lexicographically.Medium5Dynamic programmingGreedyNo attempts yet1s128 MBJudgeable
Hippity HopscotchOn an n by n grid of penny stacks, starting at (0,0) and jumping up to k cells in a row or column to a strictly larger stack, find the maximum total collected.Medium5Dynamic programmingSorting+1No attempts yet1s128 MBJudgeable
PlinkoGiven rigged Plinko boards with per-peg right-move probabilities, compute for each start and end column the number of distinct paths and the truncated percentage chance.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
RIPOFFA token moves 1 to S squares per turn and must exit a board of N labeled squares within T turns; maximize the total of the squares landed on.Medium5Dynamic programmingSliding windowNo attempts yet1s128 MBJudgeable
Signal StrengthFind the maximum signal strength reaching switch N-1 from switch 0 through a switch network with gain or loss multipliers on nodes and edges.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable
RailroadGiven two sequences, decide whether a target sequence can be formed by repeatedly taking the front car of either train; once one train empties, the rest follow in order.Medium5Dynamic programmingTwo pointers+2No attempts yet1s128 MBJudgeable
PERMSFor each query (n, k), count permutations of 1..n having exactly k inversions, with n up to 18 and k up to 200.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Sequence WalkingGiven two ascending integer sequences, find the maximum sum of a forward walk that may switch sequences at shared values.Medium5Dynamic programmingTwo pointersNo attempts yet1s128 MBJudgeable
Robots on a GridCount monotone right/down paths from the top-left to the bottom-right of an n by n grid with blocked cells, modulo 2^31-1, and report whether the goal is reachable at all, or reachable only with up and left moves allowed.Medium5Dynamic programmingDFS+2No attempts yet1s128 MBJudgeable
lsGiven a wildcard pattern where * matches any run of characters, print the input file names that match it, keeping input order.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Rig PlacementGiven n oil fields, a per-field investment cap m, and a total budget B, pick an investment amount for each field so total oil is maximized.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Study DaysDistribute H study hours among n courses, each with 10 grade thresholds, to maximize the average grade point, rounded to two decimals.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Yes or No?Pick between l and r questions to answer Yes, maximizing the sum of per-question expected correct probabilities, and report the maximum expectation to two decimals.Medium5Dynamic programmingSorting+2No attempts yet1s128 MBJudgeable
Biomedical EngineeringGiven a target string and a set of reusable component strings, find the minimum number of components whose concatenation equals the target, or report that it is impossible.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
GerrymanderingSplit n precincts, each with P and Q vote counts, into two nonempty districts; find how many districts P can win (0, 1, or 2).Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
SoccerCompute probability distribution of final scores after up to T seconds of a stochastic soccer simulation with passing, stealing, shooting, and absorbing states.Medium5ProbabilityDynamic programming+2No attempts yet2s128 MBJudgeable
Battleground PreservationGiven past battle results with costs, find the cheapest chain of victories between two fighters and decide the winner, or output FIGHT! if neither dominates.Medium5GraphShortest path+2No attempts yet1s128 MBJudgeable
Life ConnectionsGiven an undirected friendship graph, count the distinct shortest paths between each queried pair of nodes, where path length counts nodes.Medium5GraphBFS+2No attempts yet1s128 MBJudgeable
MessageGiven error and succession probabilities for a Martian alphabet, find the most likely original word for each intercepted message using maximum likelihood.Medium5Dynamic programmingProbabilityNo attempts yet1s128 MBJudgeable
Stock MarketFind the contiguous subarray with the largest sum and report its 1-based start and end indices, breaking ties by smallest start then smallest end.Medium5Dynamic programmingGreedyNo attempts yet1s256 MBJudgeable
Venus RoverChoose which stones to collect so total value is maximized, given limits on time and total lifted mass.Medium5Dynamic programmingNo attempts yet1s128 MBJudgeable
FashionistaFor each day pick any clothing whose temperature range covers that day's high, maximizing the sum of absolute flashiness differences between consecutive days.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
JOI FlagCount fillings of an M by N grid with J, O, I (some cells fixed) that contain at least one L shape: J with O to its right and I below, modulo 100000.Medium5Dynamic programmingCombinatorics+2No attempts yet5s128 MBJudgeable
Commute RouteCount monotone lattice paths from (1,1) to (w,h) that never turn at two consecutive intersections, modulo 100000.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
StrollSimulate the letters on a grid as N successive walks from the top-left, and report the endpoint of the N-th walk.Medium5SimulationDynamic programming+1No attempts yet2s128 MBJudgeable
Longest Common SubstringGiven two uppercase strings of length up to 4000, find the length of the longest substring that occurs contiguously in both.Medium5Dynamic programmingString+2No attempts yet2s256 MBJudgeable
FloodgatesEach gate drains Fi per hour at fixed cost Ci when opened. For each query (V, T), find the minimum total cost whose combined capacity Fi*T covers V.Medium5Brute forceGreedy+2No attempts yet1s128 MBJudgeable
Child PlayGiven domino-like slabs, orient and order them so both rows sum equally, discarding one slab only if necessary and preferring the smallest minimum half.Medium5Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
SupermarketGiven a shopping list and products in path order, buy the list items in order from later positions at minimum total cost, or report impossible.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Milk SchedulingGiven task durations and precedence constraints that form a DAG, find the minimum makespan when unlimited workers milk cows in parallel.Medium5GraphTopological sort+2No attempts yet1s128 MBJudgeable
BookshelfPartition the books in order into shelves whose widths sum to at most L, minimizing the total of each shelf's maximum height.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Hay For SaleGiven a wagon capacity and a list of hay bale volumes, find the largest total volume not exceeding the capacity that can be formed by choosing whole bales.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Cow Digit GameFor each starting number, players alternately subtract its largest or smallest nonzero digit, and the player who reaches 0 wins; decide if the first player wins.Medium5Dynamic programmingGame theory+2No attempts yet1s128 MBJudgeable
Cow CashCount the number of unordered ways to make an amount N using V coin denominations, where each coin can be used any number of times.Medium5Dynamic programmingCombinatorics+1No attempts yet1s128 MBJudgeable
Charm BraceletChoose a subset of N charms, each with a weight and a desirability, so that total weight stays within M and total desirability is maximized.Medium5Dynamic programmingArray+2No attempts yet1s128 MBJudgeable
Cow ContestGiven the winners of head-to-head matches, count how many cows have a skill rank that is fully forced by the results.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable
Cow TravellingCount the number of walks of exactly T steps on a grid from a start cell to a target cell, where each step moves to a vertically or horizontally adjacent open cell.Medium5Dynamic programmingMatrix+2No attempts yet1s128 MBJudgeable
ATM PIN TheftGiven a sequence of observed key presses (digits and at most one backspace), count the four-digit PINs that could produce exactly that sequence of pressed keys.Medium5Dynamic programmingCombinatorics+2No attempts yet1s128 MBJudgeable
Hopeless CoachGiven past win, draw, and loss counts, find the probability that the team earns at least P points over the next N matches.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
String ComputerCompute the minimum number of single-character insert, delete, or change operations needed to turn one string into another.Medium5Dynamic programmingString+2No attempts yet1s128 MBJudgeable
Extrapolation Using a Difference TableExtend a sequence by k steps using a polynomial difference table, always assuming the highest-order differences stay constant, and print the (n+k)-th term.Medium5MathDynamic programming+2No attempts yet1s128 MBJudgeable
El DoradoCount the increasing subsequences of length exactly k in a sequence of n distinct numbers, for several test cases.Medium5Dynamic programmingArray+1No attempts yet1s128 MBJudgeable
A Game with MarblesEach move takes one marble from a bowl and, if it is not bowl 1, adds one marble to every lower-numbered bowl; count the total moves until all bowls are empty.Medium5Dynamic programmingMath+1No attempts yet1s128 MBJudgeable
France '98Given win probabilities for every pair of 16 teams and a fixed bracket, compute each team's probability of winning the single-elimination tournament.Medium5Dynamic programmingProbability+2No attempts yet1s128 MBJudgeable
Humble NumbersFor each n up to 5842, print the nth number whose only prime factors are 2, 3, 5, or 7, formatted with the correct English ordinal suffix.Medium5Dynamic programmingMath+2No attempts yet1s128 MBJudgeable
Spiderman's WorkoutAssign plus or minus signs to the distances so the partial sums stay at or above 0 and return to 0 at the end, minimizing the peak height.Medium5Dynamic programmingGreedy+2No attempts yet1s128 MBJudgeable
Median Weight BeadGiven weighted comparisons between beads, count how many beads cannot be the median because at least (N+1)/2 beads are known heavier or lighter.Medium5GraphDFS+2No attempts yet1s128 MBJudgeable