• Codeforces Beta Round #95 (Div. 2) C. The World is a Theatre 组合数学


    C. The World is a Theatre

    There are n boys and m girls attending a theatre club. To set a play "The Big Bang Theory", they need to choose a group containing exactly t actors containing no less than 4 boys and no less than one girl. How many ways are there to choose a group? Of course, the variants that only differ in the composition of the troupe are considered different.

    Perform all calculations in the 64-bit type: long long for С/С++, int64 for Delphi and long for Java.

    Input

    The only line of the input data contains three integers nmt (4 ≤ n ≤ 30, 1 ≤ m ≤ 30, 5 ≤ t ≤ n + m).

    Output

    Find the required number of ways.

    Please do not use the %lld specificator to read or write 64-bit integers in С++. It is preferred to use cin, cout streams or the %I64d specificator.

    Examples
    input
    5 2 5
    output
    10
    input
    4 3 5
    output
    3
    思路:在4个男生1个女生的基础上暴力求组合数;不好描述见代码;
       
    #include<iostream>
    #include<cstdio>
    #include<cmath>
    #include<string>
    #include<queue>
    #include<algorithm>
    #include<stack>
    #include<cstring>
    #include<vector>
    #include<list>
    #include<set>
    #include<map>
    using namespace std;
    #define ll long long
    #define inf 2000000001
    int scan()
    {
        int res = 0 , ch ;
        while( !( ( ch = getchar() ) >= '0' && ch <= '9' ) )
        {
            if( ch == EOF )  return 1 << 30 ;
        }
        res = ch - '0' ;
        while( ( ch = getchar() ) >= '0' && ch <= '9' )
            res = res * 10 + ( ch - '0' ) ;
        return res ;
    }
    ll combine1(ll n,ll m) //计算组合数C(n,m)
    {
        ll sum=1; //线性计算
        for(ll i=1,j=n;i<=m;i++,j--)
            sum=sum*j/i;
        return sum;
    }
    int main()
    {
        ll x,y,z,i,t;
        scanf("%I64d%I64d%I64d",&x,&y,&z);
        int b=4,g=z-4;
        ll ans=0;
        for(i=4;i<=x;i++)
        {
            b=i;
            g=z-i;
            if(g>y||g<1)continue;
            ans+=combine1(x,b)*combine1(y,g);
        }
        cout<<ans<<endl;
        return 0;
    }
    View Code
  • 相关阅读:
    hdu 1998 奇数阶魔方(找规律+模拟)
    巧用百度Site App新组件为企业官网打造移动站
    POJ 1276 Cash Machine
    Unity3D中使用MiniJson解析json的例子
    设计模式读书笔记-----单例模式
    android 常用资料
    Objective-C之run loop详解
    icon 图标下载
    揭开Html 标签的面纱,忘不了的html .
    12157
  • 原文地址:https://www.cnblogs.com/jhz033/p/5444307.html
Copyright © 2020-2023  润新知