Again the algorithm is from [MathBlog](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.