Simple C++ dp sol


#1
int Solution::solve(int n, int s) {
    int dp[n+1][s+1];
    memset(dp,0,sizeof dp);
    
    for(int i=1;i<=s;i++){
        dp[1][i]=(i<=9);
    }
    
    for(int i=2;i<=n;i++){
        for(int j=1;j<=s;j++){
            for(int k=0;k<=9&&j-k>=0;k++){
                dp[i][j]+=dp[i-1][j-k];
                dp[i][j]%=(int)(1e9+7);
            }
        }
    }
    return dp[n][s];
}

#2

your code has few bugs

int Solution::solve(int A, int B) {
vector<vector> V(A+1,vector (B+1,0));
for(int i=0;i<=9&&i<=B;i++)
V[1][i]=1;
for(int i=2;i<=A;i++){
for(int j=0;j<=B;j++){
for(int k=(i==A);k<=9&&k<=j;k++){
V[i][j]+=V[i-1][j-k];
V[i][j]%=(int)(1e9+7);
}
}
}
return V[A][B];
}


#3

If you are talking about sum=0 then its handled by memset. I have submitted same sol.