dynamic programming, the same as Fibonacci array