function ncomb = multinomial_coef1 ( nfactor, factor )

%*****************************************************************************80
%
%% multinomial_coef1() computes a multinomial coefficient.
%
%  Discussion:
%
%    The multinomial coefficient is a generalization of the binomial
%    coefficient.  It may be interpreted as the number of combinations of
%    N objects, where FACTOR(1) objects are indistinguishable of type 1,
%    ... and FACTOR(NFACTOR) are indistinguishable of type NFACTOR,
%    and N is the sum of FACTOR(1) through FACTOR(NFACTOR).
%
%    NCOMB = N! / ( FACTOR(1)! FACTOR(2)! ... FACTOR(NFACTOR)! )
%
%    The log of the gamma function is used, to avoid overflow.
%
%  Licensing:
%
%    This code is distributed under the MIT license.
%
%  Modified:
%
%    07 March 2016
%
%  Author:
%
%    John Burkardt
%
%  Input:
%
%    integer NFACTOR, the number of factors.
%    1 <= NFACTOR.
%
%    integer FACTOR(NFACTOR), contains the factors.
%    0.0 <= FACTOR(I).
%
%  Output:
%
%    integer NCOMB, the value of the multinomial coefficient.
%

%
%  The factors sum to N.
%
  n = sum ( factor(1:nfactor) );

  facn = gammaln ( n + 1 );

  for i = 1 : nfactor

    facn = facn - gammaln ( factor(i) + 1 );

  end

  ncomb = round ( exp ( facn ) );

  return
end
