Little Gretchen is making tin soldiers stand at attention in a
single line. She is an egalitarian general, freely mixing soldiers of
different ranks. For example, if she had two lieutenants, two sergeants,
and one private, she could line them up in the following 16 ways.
llpss
llsps
llssp
lplss
lpsls
lslps
lslsp
lspls
lspsl
lsslp
lsspl
pllss
sllps
sllsp
slpls
slslp
Before you object that the list is incomplete, you should know that
Gretchen considers mirror images to be equivalent. For example, since
"sspll" is the same as "llpss" from back to front, she counts them as one.
You are given a int[] containing the number of soldiers of
each rank. Return an int stating the number of ways they can be lined up, ignoring reflections.
|