Solve my first DP problem in Haskell