Implement using dynamic programming as well.