Recursively find the number of combinations

Combination number calculation formula:
Insert picture description here
recursive formula:
Insert picture description here

Code template:

#include <iostream>
using namespace std;
const int N = 1010;
int c[N][N];

int main()
{
    
    
    int a,b;
    cin>>a>>b;//a在下,b在上
    for (int i = 0;i<N;i++)
        for (int j = 0;j<=i;j++)
        {
    
    
            if (!j) c[i][j] = 1;
            else c[i][j] = c[i-1][j]+c[i-1][j-1];
        }
        cout<<c[a][b]<<endl;
        return 0;
}

Guess you like

Origin blog.csdn.net/m0_51955470/article/details/114154287