Efficient Matlab implementation of Multinomial Coefficient

后端 未结 4 837
栀梦
栀梦 2021-02-11 07:35

I want to calculate the multinomial coefficient:

\"enter

where it is satisifed

4条回答
  •  借酒劲吻你
    2021-02-11 08:07

    Another approach is to use Yannis Manolopoulos iterative method. Suppose we have a vector k with the multinomial entries.

    function N = multicoeff (k),
      n=sum(k); 
      [_,imax]=max(k); 
      num=[n:-1:n-k(imax)-1]; 
      den=[]; k(imax)=[]; 
      for i=1:length(k), den=[den 1:k(i)]; endfor; 
      N=prod(num./den);
    endfunction
    

    example

    octave:2> k = [5 4 3];
    octave:3> multicoeff (k)
    ans =  27720
    

    Reference: Yannis Manolopoulos. Binomial coefficient computation. ACM SIGCSE Bulletin, 34(4):65, December 2002. doi: 10.1145/820127.820168. URL https: //doi.org/10.1145/820127.820168.

提交回复
热议问题