Statistics

Problem Statement for "TinSoldiers"

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 int[] containing the number of soldiers of each rank. Return an int stating the number of ways they can be lined up, ignoring reflections.

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

  1. {2, 2, 1}

    Returns: 16

    This case is illustrated above.

  2. {2, 2, 2}

    Returns: 48

    One more private makes for many more line-ups.

  3. {5}

    Returns: 1

    There is only one way to line up five soldiers of the same rank.

  4. {5, 1}

    Returns: 3

    Look out for reflections!

  5. {4, 5}

    Returns: 66

    Here we have four soldiers of one rank, and five soldiers of another.

  6. {4, 2, 2, 5, 4}

    Returns: 643245120

    In this case, Gretchen can spend months and years lining up her soldiers.

  7. {5, 1, 1, 1}

    Returns: 168

  8. {5, 4, 3, 3}

    Returns: 6306300

  9. {3, 2}

    Returns: 6

  10. {2, 1, 4}

    Returns: 54

  11. {1, 4, 2, 4, 4}

    Returns: 23648940

  12. {1, 4}

    Returns: 3

  13. {2, 1, 2}

    Returns: 16

  14. {3, 3, 4}

    Returns: 2100

  15. {5, 5, 1, 4}

    Returns: 1891890

  16. {1, 5, 3}

    Returns: 252

  17. {4, 1, 4, 2}

    Returns: 17340

  18. {5, 2, 4, 3}

    Returns: 1261260

  19. {1, 5, 1, 2, 4}

    Returns: 540540

  20. {4, 4, 2, 1, 1}

    Returns: 207900

  21. {1, 5, 4, 3}

    Returns: 180180

  22. {4, 5, 5}

    Returns: 126126

  23. {5, 3, 2, 4}

    Returns: 1261260

  24. {5, 2, 2, 4}

    Returns: 270360

  25. {5, 4, 2}

    Returns: 3480

  26. {2, 1, 3, 2, 5}

    Returns: 1081080

  27. {2, 2, 1}

    Returns: 16

  28. {1, 2}

    Returns: 2

  29. {2, 4, 4, 4, 3}

    Returns: 1072073520

  30. {3, 4, 4}

    Returns: 5790

  31. {3, 3, 4}

    Returns: 2100

  32. {3, 4, 1}

    Returns: 140

  33. {3, 4, 4}

    Returns: 5790

  34. {2, 4, 5}

    Returns: 3480

  35. {4, 4, 3, 2}

    Returns: 450540

  36. {1, 2}

    Returns: 2

  37. {1, 2, 3, 2, 5}

    Returns: 1081080

  38. {2, 3}

    Returns: 6

  39. {5, 3}

    Returns: 28

  40. {5, 1}

    Returns: 3

  41. {5, 1, 2, 1, 3}

    Returns: 166320

  42. {4, 4}

    Returns: 38

  43. {4, 2}

    Returns: 9

  44. {4, 4, 5, 3}

    Returns: 25225200

  45. {2, 5, 1}

    Returns: 84

  46. {4, 5, 1, 5}

    Returns: 1891890

  47. {4, 4}

    Returns: 38

  48. {4, 4}

    Returns: 38

  49. {2, 4, 5, 3}

    Returns: 1261260

  50. {3, 2, 5, 3}

    Returns: 360360

  51. {1,4,4,4,5}

    Returns: 1929727800

  52. { 5, 5, 5, 4 }

    Returns: 1466593128

  53. { 4, 4, 3, 3, 3 }

    Returns: 1429428000

  54. { 3, 3, 2, 4, 1 }

    Returns: 1801800

  55. { 5, 3, 3, 3, 3 }

    Returns: 1143542400

  56. { 4, 2, 1 }

    Returns: 54


This problem statement is the exclusive and proprietary property of TopCoder, Inc. Any unauthorized use or reproduction of this information without the prior written consent of TopCoder, Inc. is strictly prohibited. (c)2024, TopCoder, Inc. All rights reserved.
This problem was used for: