Changed the dp implementation