Aliens DP: A Penalty Removes a Dimension, Convexity Gives It Back
Suppose a DP must use exactly segments. Keeping the segment count as a state often costs an extra factor of . Aliens DP assigns a price to every segment and solves an unrestricted problem instead. The subtle part is recovering the exact-count answer: monotonicity alone is not enough.
The lower envelope
Let be the minimum original cost using exactly segments. For a penalty , an oracle computes
Each possible count contributes a line of slope . Their lower envelope is concave as a function of . As the penalty grows, the selected count cannot increase.
To prove this, let counts be optimal at . Add their optimality inequalities. The original costs cancel, leaving . Thus . This monotonicity justifies binary-searching a count boundary.
Why exact recovery needs more
For every penalty,
It is a lower bound. Equality holds when the count- point lies on a supporting line of the discrete cost curve. A sufficient condition is discrete convexity: the differences are nondecreasing over the feasible counts.
If the sequence is not convex, the method can skip a count entirely. For the counterexample , count two is never optimal for any penalty. The envelope only sees counts one and three. Recovering a value by interpolation would return the lower convex envelope, not the true answer 10.
This is why “the optimal count changes monotonically” is not a complete correctness proof. It is true even for this failing example.
convex example
Partition four unit weights into nonempty contiguous segments. Charge each segment the square of its weight sum. The exact-count costs are
The differences are , so this instance is discretely convex. At penalty two, counts two, three, and four all have penalized cost 12. For , subtracting gives the correct cost six, even if the oracle returns count four because of its tie-breaking rule.
The flat supporting face explains how valid skipped counts can occur in a convex instance: all intermediate points lie on the same line. A skipped count above that line would not be recoverable.
Build the oracle with explicit ties
For segment cost , the penalized recurrence is
Store (cost,count) at each state. Compare cost first, then consistently prefer either fewer or more segments. Choose a convention that matches the binary-search predicate and document it.
candidate.cost = D[j].cost + segment_cost(j + 1, i) + penaltycandidate.count = D[j].count + 1take lower cost; on equality, take larger countThe penalty removes the count dimension but does not optimize the transition over . If the oracle is quadratic, a logarithmic number of oracle calls can still be too slow. A convex hull trick, Monge optimization, or another independently justified method may be needed inside it.
Integer penalties and boundaries
When costs are integers and discrete convexity holds, adjacent marginal costs are integers. A supporting penalty can therefore be chosen at an integer boundary. Binary-search the largest penalty whose more-counts oracle still returns at least , with proven bounds that bracket the transition. Handle at the ends of the feasible range separately if your search relies on a transition existing.
Use sufficiently wide arithmetic for penalty * count, not merely for the original costs. For large constraints, signed 128-bit intermediates can prevent an otherwise invisible overflow in comparisons.
Exercise. Construct an exact-count cost sequence with a strict convex corner at , another with a linear face containing , and a third with above its lower envelope. For each, list the oracle’s chosen count over penalties from -5 to 5 and explain whether recovery is valid.
Support & Share
If this article helped you, please share or support!





























































Conversation
Comments powered by Waline