递推求组合数

组合数计算公式:
在这里插入图片描述
递推公式:
在这里插入图片描述

代码模板:

#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;
}

猜你喜欢

转载自blog.csdn.net/m0_51955470/article/details/114154287
今日推荐