Target sum problem leetcode

problem link

this is showing the error…
Line 44: Char 50: runtime error: signed integer overflow: -1094795586 + -1094795585 cannot be represented in type ‘int’ (solution.cpp)
SUMMARY: UndefinedBehaviorSanitizer: undefined-behavior prog_joined.cpp:53:50

plz correct my code along with explaination…also modify the code to handle cases where there are 0 in array.

why are to allocating memory for average of target and actual sum?
your DP recurrence is not correct too!

isnt this problem same as the subset diff problem??that is why i have applied that approach here becaue if we take all minus common then it becomes that only…

yes this can be done with that!
you are having overflow in value!
don’t add them, instead apply OR and take dp array of type bool

how will i count total if i take bool and or??i need to output the total…
reply at the earliest…

Yes we have to count!, see your recurrence is incorrect!
I’ve also provided my code to see for DP recurrence(you can also make out bottom up code from given top down)

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.