Video failed to load

Aliens DP: A Penalty Removes a Dimension, Convexity Gives It Back

578 words
3 minutes
Aliens DP: A Penalty Removes a Dimension, Convexity Gives It Back

Suppose a DP must use exactly kk segments. Keeping the segment count as a state often costs an extra factor of kk. 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 CjC_j be the minimum original cost using exactly jj segments. For a penalty λ\lambda, an oracle computes

F(λ)=min⁡j(Cj+λj).F(\lambda)=\min_j(C_j+\lambda j).

Each possible count contributes a line of slope jj. Their lower envelope is concave as a function of λ\lambda. As the penalty grows, the selected count cannot increase.

To prove this, let counts a,ba,b be optimal at λ1<λ2\lambda_1<\lambda_2. Add their optimality inequalities. The original costs cancel, leaving (λ2−λ1)(b−a)≤0(\lambda_2-\lambda_1)(b-a)\le0. Thus b≤ab\le a. This monotonicity justifies binary-searching a count boundary.

Why exact recovery needs more#

For every penalty,

F(λ)−λk≤Ck.F(\lambda)-\lambda k\le C_k.

It is a lower bound. Equality holds when the count-kk point lies on a supporting line of the discrete cost curve. A sufficient condition is discrete convexity: the differences Cj+1−CjC_{j+1}-C_j are nondecreasing over the feasible counts.

If the sequence is not convex, the method can skip a count entirely. For the counterexample C1=0,C2=10,C3=0C_1=0,C_2=10,C_3=0, 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

C1=16,C2=8,C3=6,C4=4.C_1=16,\quad C_2=8,\quad C_3=6,\quad C_4=4.

The differences are −8,−2,−2-8,-2,-2, so this instance is discretely convex. At penalty two, counts two, three, and four all have penalized cost 12. For k=3k=3, subtracting 2⋅32\cdot3 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 w(l,r)w(l,r), the penalized recurrence is

Di=min⁡j<i{Dj+w(j+1,i)+λ}.D_i=\min_{j<i}\{D_j+w(j+1,i)+\lambda\}.

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) + penalty
candidate.count = D[j].count + 1
take lower cost; on equality, take larger count

The penalty removes the count dimension but does not optimize the transition over jj. 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 kk, with proven bounds that bracket the transition. Handle kk 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 k=2k=2, another with a linear face containing k=2k=2, and a third with C2C_2 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!

Sponsor
Aliens DP: A Penalty Removes a Dimension, Convexity Gives It Back
https://blog.wsh.moe/posts/aliens-dp/
Author
Wsh
Published at
2026-10-24

Comments

LEAVE A NOTE

Join the conversation

Markdown supported

Be kind. Good conversations start with you.

Conversation

Loading conversation…

Comments powered by Waline

Profile Image of the Author
Wsh
Nice to meet you! Hello, I'm Wsh.
Announcement
Any news or updates will be shared here, so check back anytime! Thanks for stopping by, meow >.<
Categories
Tags
Site Statistics
Posts
27
Categories
7
Tags
69
Total Words
124,615
Running Days
0 days
Last Activity
0 days ago
Site Info
Build Platform
Vercel
Blog Version
Firefly v6.16.8
License
CC BY-NC-SA 4.0
Table of Contents