Abridged Problem Statement : Given a1, a2, ..., an, find the number of permutations of these numbers such that |a1 - a2| + |a2 - a3| + ... + |an - 1 - an| ≤ L where L is a given integer.
The editorial given is quite brief and the sample code is nearly unreadable. I have no idea how to do the dp.
Can anyone explain the solution? Thanks.
UPD : Thanks to ffao for the hint! I finally got how the dp works. The unobfuscated code with comments is here.