I don't seem to understand what is wrong in this code. My submission is failing for values 75,22. PLease help


#1

using ll=long long;
int Solution::solve(int A, int B) {
ll ID=A;
ll SUM=B;
// cout<<A<<" “<<B<<” ";
vector <vector> S(ID+1, vector (SUM+1));
if (SUM==0&& ID==1)
return 0;

for (ll j=0;j<=SUM;j++){
    S[0][j]=0;
    // S[0][0]=1;
    if(j<10)
        S[1][j]=1;
    
    else
        S[1][j]=0;
    S[1][0]=0;
}
for (ll i=2;i<=ID;i++){
    for(ll j=0;j<=SUM;j++){
        S[i][j]=0;
        for(int k=0;k<10;k++){
            if(j-k>=0)
                S[i][j]+=S[i-1][j-k];
        }
        
    }
}

return S[ID][SUM]%int(1e9+7);

}


#2

My solution: this is also failing, I don’t seem to get the mistake. This is probably failing for large test cases.

  int Solution::solve(int n, int sum) {
  int dp[n+1][sum+1];
  
  for(int i = 0; i<n+1; i++)
  {
      for(int j = 0; j<sum+1; j++)
      {
          dp[i][j] = 0;
      }
  }
  for(int i = 0; i<=9 && i<sum+1; i++)
  {
      dp[1][i] = 1;
  }
  for(int i = 2; i<n+1;i++)
  {
      for(int j = 0; j<sum+1; j++)
      {
          for(int k = 0; k<j; k++)
          dp[i][j] = (dp[i][j]%1000000007 + dp[i-1][j-k]%1000000007)%1000000007;
      }
  }
  return dp[n][sum];

}