Not getting the the correct answer


please correct my code and tell my mistake that i done in my code

you have to make size of dp array = n+1
because if you make size of array =n then
you can only access the index from 0 to n-1 but
you are also using dp[n] so make size of array n+1

i updated dp[n] with dp[n+1] but still not working, please check and do necessary changes in my code

it is giving correct output after changing size of array
see this

Modified Code