I have understood the approach but I cannot seem to figure out why my code is not working as expected.

```
int Solution::coinchange2(vector<int> &A, int B) {
vector<int> dp(B+1, 0);
sort(A.begin(), A.end());
dp[0]=1;
for(int i=1; i<=B; i++){
for(int j=0; j<A.size(); j++){
if(i-A[j]>=0)
dp[i]= (dp[i] + dp[i-A[j]])%1000007;
}
}
// for(int i=0; i<=B;i++)
// cout <<dp[i]<<" ";
return dp[B];
}
```