ENG  RUSTimus Online Judge
Online Judge
Problems
Authors
Online contests
About Online Judge
Frequently asked questions
Site news
Webboard
Links
Problem set
Submit solution
Judge status
Guide
Register
Update your info
Authors ranklist
Current contest
Scheduled contests
Past contests
Rules
back to board

Discussion of Problem 1114. Boxes

jedimastex combinatoric solution, which works(already:)) [5] // Problem 1114. Boxes 23 Jun 2004 20:55
#include <iostream>

using namespace std;

unsigned __int64 c(unsigned __int64, unsigned __int64);

unsigned __int64 a,b,n,ans;

int main()
{
    cin >> n >> a >> b;
    ans=c(n+a,a)*c(n+b,b);
    cout << ans;
    return 0;
}

 unsigned __int64 c(unsigned __int64 l, unsigned __int64 k)
{
    unsigned __int64 i,r=1,d=l-k;
    for (i=1;i<=d;i++) {r*=(i+k); r/=i;}
    return r;
}





Edited by author 24.06.2004 19:00
There is another formula but if I write it I don't think it will really help you...
Why do you think so?
Interestingly

N 1 1 = (n+1)^2 and 1 a b when a=b  answer (a+1)^2;

5 1 1 = true answer 36 and 1 5 5  = 36

etc ^_^

Edited by author 26.07.2010 02:34

Edited by author 26.07.2010 02:34
because the answer = (how many ways you can put no more than A red balls into N boxes)*(how many ways you can put no more than B blue balls into N boxes)
and (how many ways you can put no more than A red balls into N boxes)=C(a+n,a)//it is like there are a+n stickes in order, and you pick up n sticks so the rest sticks are divided into n+1 parts,the last part is for the balls which is not put in the box,and the 1st to nth part is for box 1st to nth
and the same for (how many ways you can put no more than B blue balls into N boxes)
This problem has a much easier(to understand) dp solution.