joj 2296 Boxes

來源:互聯網
上載者:User
文章目錄
  • Input
  • Output
  • Sample Input
  • Sample Output
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. */

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.