Yes, it looks wrong.
It should be simple. In the Ans method, check whether you’ve already calculated the answer for this value of i (i.e. does DP have a value for this i?), if you have return it. Otherwise calculate the answer, store it in the DP array, then return it.