文学城论坛
+A-

Recursive functions for several variables.

jinjing 2010-09-07 18:19:35 ( reads)

The question is same as putting 20 balls to 4 different boxes.only 16 balls.
We use f(m,n)the number putting m balls to n different boxes.
I do your first Q.Finding f(16,4).
f(1,1)=1,...f(m,1)=1...f(m,n)=f(m,n-1)+f(m-1,n-1)+...+f(0,n-1). f(m,2)=m+1.f(m,3)=m(m+1)/2 +m+1.
f(16,4)=Sigma f(i,3) i from 0 to 16=1+3+6+10+15+21+....+136+153=959.You check it.
Second Q is Sigma [f(i,4)] from 0 to 20]
If every ball is different we can use generating function solving it.

跟帖(0)