Dynamic Programming21 sections · 916 units
Open in Course

Codeforces 319C Kalila and Dimna - Problem Statement

CF 319C

There are nn trees with heights a1,,ana_1, \ldots, a_n and costs b1,,bnb_1, \ldots, b_n. You start at tree 1 and want to reach tree nn. From tree ii, jumping to tree j>ij > i costs biajb_i \cdot a_j. Find the minimum total cost. The cost mixes bib_i (source) and aja_j (destination).

This product structure is the CHT signal. The problem statement specifies that heights aia_i are strictly increasing and costs bib_i are strictly decreasing. This ordering is exactly what CHT needs. Let me show you how to set up the DP.