Help explaining the code please

Hey guys this is the problem I have to solve and explain, can you please help me out a little with it?
"Write a C++ program that accepts n different numbers (0 to 100) and s which is equal to the sum of the n different numbers.
Your job is to find the number of combination of n numbers and the same number can not be used for one combination."

Example:
Here n = 3 and s = 6:
1 + 2 + 3 = 6
0 + 1 + 5 = 6
0 + 2 + 4 = 6
Output: Number of combination: 3

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
int n,s;
 
long long int dp[10][1010];
 
int main(void){
    dp[0][0]=1LL;
    rep(i,101){
        for(int j=8;j>=0;j--)rep(k,1010){
            if(k+i<=1010)
                dp[j+1][k+i]+=dp[j][k];
        }
    }
    cout << "Input n and s: ";
    cin >> n >> s;
    cout << "\nNumber of combination: ";
    cout << dp[n][s] << endl;
Have you learned about recursion? This can be solved pretty easily that way.

Using your example, one set of solutions is to start with 1, and then find all solutions for s' = s-1 = 5.
Topic archived. No new replies allowed.