recursive DP approach, very fast