joj 2296 Boxes

Result TIME Limit MEMORY Limit Run Times AC Times JUDGE
3s 8192K 178 42 Standard

N boxes are lined up in a sequence (1 <= N <= 20). You have A red balls and B blue balls (0 <= A <= 15, 0 <= B <= 15). The red balls (and the blue ones) are exactly the same. You can place the balls in the boxes. It is allowed to put in a box, balls of the two kinds, or only from one kind. You can also leave some of the boxes empty. It's not necessary to place all the balls in the boxes. Write a program, which finds the number of different ways to place the balls in the boxes in the described way.

Input

Input contains many lines, every line with three integeres N, A and B separated by space.

Output

The result of your program must be an integer writen on the only line of output.

Sample Input

2 1 1

Sample Output

9

/*

一道简单的组合数学题,公式是c(n,a)*c(n,b),但是题目涉及到的数字较大如果不用高精度就得是unsigned long long而比赛的时候我一直拿double做,在输入是20 15 15时答案是末尾6000的数明显不是c(20,15)^2这样的平方数,找不到错误原因。

*/

//ac代码

  1. #include <cstdio>
  2. #include <iostream>
  3. #include <cmath>
  4. using namespace std;
  5. int main ( )
  6. {
  7.      unsigned long long  n,a,b;
  8. while (cin>>n>>a>>b )
  9. {
  10.         unsigned long long  aa= 1,bb= 1;
  11.        unsigned long long ans= 1;
  12.         if (n )
  13.          {
  14.           for ( unsigned long long   i= 1; i<=a ; i++ )
  15.             aa= (i+n )*aa/i;
  16.          }
  17.         if (n )
  18.          {
  19.           for ( unsigned long long  i= 1 ; i<=b ; i++ )
  20.             bb= (i+n )*bb/i;
  21.          }
  22.         ans=bb*aa;
  23.              printf ( "%llu/n",ans );
  24. }
  25. return 0;
  26. }
  27. /*
  28. 2 1 1
  29. 2 2 2
  30. 20 15 15
  31. */

 

你可能感兴趣的:(joj 2296 Boxes)