Project Euler 31, simple dynamic programming