Can't understand the error of the money change problem

Just one test case of the money change problem passes and rest all give a run error. Please help can’t figure out where the problem lies.

hey @knownowworld please share your code through ide.codingblocks.com

I have pasted the code in the ide

after you paste the code, click on save and then copy the link and paste it here.

#include
#include

using namespace std;

int coinWays(int *S, int n, int amt,int dp[][1000])
{

 if (amt == 0)
    return 1;

if (amt < 0)
    return 0;


if (n <=0 && amt >= 1)
    return 0;

int sum = 0;
sum = accumulate(S, S+n, sum);

if(dp[sum][amt] != 0)
{
    return dp[sum%(1000000000 + 7)][amt%(1000000000 + 7)];
}

dp[sum%(1000000000 + 7)][amt%(1000000000 + 7)] = coinWays( S, n - 1, amt,dp ) + coinWays( S, n, amt-S[n-1],dp );

return dp[sum%(1000000000 + 7)][amt%(1000000000 + 7)]%(1000000000 + 7);

}

int main() {

int t;
cin>>t;

int amt;
int n;
int *a;
int *ans = new int[t];
*ans = {0};

for(int i=0;i<t;i++)
{
int dp1[1000][1000] = {0};
cin>>n;
a = new int[n];
for(int j=0;j<n;j++)
{
cin>>a[j];
}
cin>>amt;
ans[i]=coinWays(a, n, amt,dp1);
free(a);

}

for(int i=0;i<t;i++)
cout<<ans[i]%(1000000000 + 7)<<endl;

return 0;

}

https://online.codingblocks.com/app/player/68493/content/56751/5203/code-challenge

@knownowworld use long long int instead of int and dont use accumulate instead write a look for addition and use modulo. moreover value of amt and sum can be as large as 10^6 and your array is of size 1000*1000 and you cant construct array of size 10^6 * !0^6 please try different approach.

Here is the solution following bottom up approach https://ide.codingblocks.com/s/192969:

The code link displays no code

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.