QFNU-ACM 2020.4.5 个人赛 - 补题报告

题意:有n个男孩,m个女孩,从男孩中选不少于4个男孩,女孩中选不少于1个女孩,组成人数为t的队伍,问有几种可能的组合?

思路:排列组合问题,组合数和杨辉三角形是一一对应的,根据杨辉三角来计算结果

代码:

#include <iostream>
using namespace std;
typedef long long LL;
 
LL Y[70][70];
// 构造杨辉三角
void init() {
    for(int i = 0; i <= 30; i++) {
        Y[i][0]=1;
        for(int j = 1; j <= i; j++) {
            Y[i][j] = Y[i-1][j-1] + Y[i-1][j];
        }
    }
}
int main() {
    init();
    int n, m, t;
    cin >> n >> m >> t;
    LL res = 0;
    for(int i = 4; i < t; i++) {
        res += Y[n][i] * Y[m][t-i];
    }
    cout << res << endl;
    return 0;
}

猜你喜欢

转载自www.cnblogs.com/ZhengQC/p/12637925.html