Recursive code correct, error coming in dp

code is running correctly for recursion but showing segmentaion fault when using dp.

your size of array is
int dp[1000][100000];
which is large so you have to make the dp array globally

also you have to run loop i till n and j till sum
for (int i = 0; i <=n; i++)
for (int j = 0; j <=sum; j++)
dp[i][j] = -1;

it’s still not compiling.

make size of dp array 10^3 X 10^5 =10^8
more than this will not run

you have make size of aray = 10^4 X 10^5=10^9 so it will not run

the answer is coming out to be wrong, showing no instead of yes in this test case

correct the loop

    for(int i=0;i<=n;i++)
    for(int j=0;j<=sum;j++)
    dp[i][j]=-1;