Stack overflow error

Hi, I solved the problem using recursion and I did dry run the program for some cases and it seems to work correctly. I am getting stack overflow error.
For recursion to work I need to make these many calls but it seems like the input is too large and even the required calls are filling the stack causing the overflow error.
Can you please confirm if I am thinking correctly and if yes please give me some hint that how can I reduce any call. In 1 of submissions I tried keeping the track of counts for a particular value of n so that I don’t make redundant recursive calls but that didn’t work too.