Exchange Coins Dynamic Programming

https://pastebin.com/GUf8DFZE

I’m getting a weird error for odd values in this question. Please help out.
The error I am getting is

a.out: malloc.c:2394: sysmalloc: Assertion `(old_top == initial_top (av) && old_size == 0) || ((unsigned long) (old_size) >= MINSIZE && prev_inuse (old_top) && ((unsigned long) old_end & (pagesize - 1)) == 0)’ failed.
Aborted (core dumped)

if I uncomment the line before the recursive call, it gives correct answer.

Yeah ! definitely you will get such type of errors as you created an array of “dp” of size n and asking recursive function to owe you the value of dp[n],not possible as index varies from 0 to size -1 so you have to take array of size atleast n+1 .