Caesar's Legions
MediumRating 1700Codeforces2-D Dynamic Programming
Approach hintTry it first, then revealHide
Let dp[f][h][last] count arrangements that use f footmen and h horsemen and end with the given type. Extend by a whole block of 1 to k1 footmen or 1 to k2 horsemen, switching the type each time.