prynkdhk
BAN USERpublic static int count(int n, int r, int g, int b){
int count = 0;
int x = n - (r+g+b);
if(x==0)
return fact(n)/(fact(r)*fact(g)*fact(b));
for(int i=0; i<=x; i++){
for(int j=0; j<=x-i; j++){
for(int k=0; k<=x-i-j; k++){
int p = r + i;
int q = g + j;
int s = b + k;
if(n == p+q+s)
count = count + fact(n)/(fact(p)*fact(q)*fact(s));
}
}
}
return count;
}
public static int fact(int n){
int count = 1;
for(int i=2; i<=n; i++){
count = count*i;
}
return count;
}
- prynkdhk November 01, 2014