Getting TLE with this dp solution why


#1

public class Solution {
private static final int MOD = 1000000007;
public int solve(int A, int B){
Integer [][]dp =new Integer[A+1][B+1];
int sol=solve(A,B,dp);
return sol;
}

 private int solve(int A, int B, Integer[][] dp) {
 
   if(A==0 && B==0){
     return 1;
   }
   else if(B==0 && A!=0){
     return 0;
   }
   else if(A==0 && B!=0){
    return 0;
   }
   else{
       if(dp[A][B]==null){
           int sum=0;
           for(int i=0;i<=9 && i<=B;i++){
             sum=((sum%MOD)+(solve(A-1,B-i)%MOD))%MOD;
           }
           dp[A][B]=sum;
       }
     return dp[A][B];
   }
 }

}