I’m solving this Coin Change problem on Hackerrank. I recently started doing DP but stuck on this question.

This is my code:

```
#include<iostream>
using namespace std;
int main()
{
int total, n;
cin>>total>>n;
int coins[n];
for(int i=0; i<n; i++) cin>>coins[i];
int ways[n][total+1] = {0};
ways[0][0]=1;
for(int i=1; i<=total; i++)
if (i % coins[0] == 0)
ways[0][i]=1;
for(int i=1; i<n; i++)
{
for(int j=0; j<=total; j++)
{
if(coins[i]>j)
ways[i][j] = ways[i-1][j];
else
ways[i][j] = ways[i-1][j] + ways[i][j-coins[i]];
}
}
cout<<ways[n-1][total];
return 0;
}
```

It gets accepted for most of the test cases but gives weird output on

```
15 24
49 22 45 6 11 20 30 10 46 8 32 48 2 41 43 5 39 16 28 44 14 4 27 36
```

this one. And I can’t understand why. Please help.