CodeForces 131C The World is a Theatre 组合数

看过生活大爆炸的都知道,四男一女。

所以就是男生的取法乘女生的取法


#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
#define CPY(A, B) memcpy(A, B, sizeof(A))
typedef long long LL;
typedef unsigned long long uLL;
const int MOD = 1e9 + 7;
const int INF = 0x3f3f3f3f;
const LL INFF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;
const double OO = 1e20;
const double PI = acos (-1.0);
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
using namespace std;
const int maxn=1250;
LL C (LL a, LL n) {
    LL ans=1,i;
    for (i=1; i<=a; i++) {
        ans*=n-i+1;
        ans/=i;
    }
    return ans;
}//求组合数
int main() {
    LL n,m,t,ans=0;
    scanf ("%I64d%I64d%I64d",&n,&m,&t);
    for (int i=4; i<=n; i++) {
        if (m>=t-i&&t-i>0) {
            ans+= (C (i,n) *C (t-i,m) );//ans=ans(boys)*ans(girls)
        }
    }
    printf ("%I64d",ans);
    return 0;
}


另外,组合数的其他求法:

//dp:
void init() {
    d[0][0]=1;
    for (int i=1; i<=30; ++i) {
        d[i][0]=d[i][i]=1;
        for (int j=1; j




你可能感兴趣的:(CodeForces,数学-组合数学)