Dynamic Programming21 sections · 916 units
Open in Course

Commando - Problem Statement

Classic CHT problem

Split nn soldiers into contiguous groups. Group value = ax2+bx+ca \cdot x^2 + b \cdot x + c where xx is sum of strengths in group. dp[i]dp[i] = max value for first ii soldiers.

Transition: dp[i]=maxj<i(dp[j]+f(SiSj))dp[i] = \max_{j < i}(dp[j] + f(S_i - S_j)) where SS is prefix sum. Expand f(SiSj)=a(SiSj)2+b(SiSj)+cf(S_i - S_j) = a(S_i - S_j)^2 + b(S_i - S_j) + c. Separate terms by ii and jj. Result: linear in SiS_i with slope depending on jj. Apply CHT. Handle max instead of min by negating.