The World is a Theatre

http://codeforces.com/problemset/problem/131/C

The World is a Theatre
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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.

Sample test(s)
input
5 2 5
output
10
input
4 3 5
output
3

简单数学题,排列组合。
直接暴力出来的。
注意一点就行,连乘的时候数据会溢出,所以要乘一个然后再跟着除一个。这个题就解决了。
AC代码:
#include
#include

using namespace std;

int main()
{
    int n,m,t,i,j,p,q;
    __int64 a,b,sum;
    while(scanf("%d%d%d",&n,&m,&t)!=EOF)
    {
        sum = 0;
        for(i = 4; i <= n; i++)  //男孩数量
        {
            for(j = 1; j <= m; j++)  //女孩数量
            {
                if(i+j == t)
                {
   //                 printf("%d %d\n",i,j);
                    a = b = 1;
                    if(i >= n/2)
                    {
                        q = 1;
                        for(p = n; p > i; p--)
                        {
                            a = a*p;
                            a = a/q;
                            q++;
                        }
   //                     printf("%I64d\n",a);
                    }
                    else
                    {
                        q = 1;
                        for(p = n; p > n-i; p--)
                        {
                            a = a*p;
                            a = a/q;
                            q++;
                        }
    //                    printf("%I64d\n",a);
                    }
                    if(j >= m/2)
                    {
                        q = 1;
                        for(p = m; p > j; p--)
                        {
                            b = b*p;
                            b = b/q;
                            q++;
                        }
   //                     printf("%I64d\n",b);
                    }
                    else
                    {
                        q = 1;
                        for(p = m; p > m-j; p--)
                        {
                            b = b*p;
                            b = b/q;
                            q++;
                        }
   //                     printf("%I64d\n",b);
                    }
                    sum = sum+a*b;
  //                  printf("%I64d\n",sum);
                }
            }
        }
        printf("%I64d\n",sum);
    }

    return 0;
}


你可能感兴趣的:(基础,CF,暴力)