Project Euler problem: Simple DP