Problem Statement
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
Definition
- Class:
- TinSoldiers
- Method:
- lineUps
- Parameters:
- int[]
- Returns:
- int
- Method signature:
- int lineUps(int[] rankCounts)
- (be sure your method is public)
Constraints
- rankCounts contains between 1 and 5 elements, inclusive
- each element of rankCounts is between 1 and 5, inclusive
- there are fewer than 2^31 ways for Gretchen to line up the soldiers
Examples
{2, 2, 1}
Returns: 16
This case is illustrated above.
{2, 2, 2}
Returns: 48
One more private makes for many more line-ups.
{5}
Returns: 1
There is only one way to line up five soldiers of the same rank.
{5, 1}
Returns: 3
Look out for reflections!
{4, 5}
Returns: 66
Here we have four soldiers of one rank, and five soldiers of another.
{4, 2, 2, 5, 4}
Returns: 643245120
In this case, Gretchen can spend months and years lining up her soldiers.
{5, 1, 1, 1}
Returns: 168
{5, 4, 3, 3}
Returns: 6306300
{3, 2}
Returns: 6
{2, 1, 4}
Returns: 54
{1, 4, 2, 4, 4}
Returns: 23648940
{1, 4}
Returns: 3
{2, 1, 2}
Returns: 16
{3, 3, 4}
Returns: 2100
{5, 5, 1, 4}
Returns: 1891890
{1, 5, 3}
Returns: 252
{4, 1, 4, 2}
Returns: 17340
{5, 2, 4, 3}
Returns: 1261260
{1, 5, 1, 2, 4}
Returns: 540540
{4, 4, 2, 1, 1}
Returns: 207900
{1, 5, 4, 3}
Returns: 180180
{4, 5, 5}
Returns: 126126
{5, 3, 2, 4}
Returns: 1261260
{5, 2, 2, 4}
Returns: 270360
{5, 4, 2}
Returns: 3480
{2, 1, 3, 2, 5}
Returns: 1081080
{2, 2, 1}
Returns: 16
{1, 2}
Returns: 2
{2, 4, 4, 4, 3}
Returns: 1072073520
{3, 4, 4}
Returns: 5790
{3, 3, 4}
Returns: 2100
{3, 4, 1}
Returns: 140
{3, 4, 4}
Returns: 5790
{2, 4, 5}
Returns: 3480
{4, 4, 3, 2}
Returns: 450540
{1, 2}
Returns: 2
{1, 2, 3, 2, 5}
Returns: 1081080
{2, 3}
Returns: 6
{5, 3}
Returns: 28
{5, 1}
Returns: 3
{5, 1, 2, 1, 3}
Returns: 166320
{4, 4}
Returns: 38
{4, 2}
Returns: 9
{4, 4, 5, 3}
Returns: 25225200
{2, 5, 1}
Returns: 84
{4, 5, 1, 5}
Returns: 1891890
{4, 4}
Returns: 38
{4, 4}
Returns: 38
{2, 4, 5, 3}
Returns: 1261260
{3, 2, 5, 3}
Returns: 360360
{1,4,4,4,5}
Returns: 1929727800
{ 5, 5, 5, 4 }
Returns: 1466593128
{ 4, 4, 3, 3, 3 }
Returns: 1429428000
{ 3, 3, 2, 4, 1 }
Returns: 1801800
{ 5, 3, 3, 3, 3 }
Returns: 1143542400
{ 4, 2, 1 }
Returns: 54