Again the algorithm is from [MathBlog](https://web.archive.org/web/20150326121651/http://www.mathblog.dk/project-euler-78-coin-piles/). I can't really say that I understand the algorithm fully (and the MathBlog guy says he neither). But for the best explanation you better read his article.