Statistics

Problem Statement for "StringBeads"

Problem Statement

You have beads of several different colors that are to be placed on a string, with the requirement that for any group of three adjacent beads, all three must have different colors.

You are given a int[] beads indicating how many of each color bead you have. The i-th element of beads is the number of beads of color i, where each i represents a distinct color. You are to return a long representing the number of ways they can be placed on the string, meeting the given requirement.

Definition

Class:
StringBeads
Method:
numWays
Parameters:
int[]
Returns:
long
Method signature:
long numWays(int[] beads)
(be sure your method is public)

Notes

  • The resulting arrangement of beads is linear, not circular. (Thus, the first bead on the string, and the last, are not adjacent.)

Constraints

  • beads will contain between 3 and 5 elements, inclusive.
  • Each element of beads will be between 1 and 10, inclusive.
  • The total number of beads will not exceed 35.

Examples

  1. { 1, 1, 1 }

    Returns: 6

    There are three beads, each a different color. The number of ways to arrange them is simply 3! = 6.

  2. { 1, 1, 1, 1 }

    Returns: 24

    Now with four beads, there are 4! = 24 arrangements.

  3. { 2, 1, 1 }

    Returns: 2

    Lets say that we have 2 green beads, 1 blue, and 1 red. In order to satisfy the requirement that each group of three consecutive beads have no two of the same color, the green beads must go at the beginning and end of the string. There are two ways to put the blue and the red in the middle: GRBG or GBRG.

  4. { 3, 1, 1 }

    Returns: 0

    There is no way to meet the requirement.

  5. { 3, 2, 2 }

    Returns: 2

  6. {7,7,7,7,7}

    Returns: 1206522685040520

  7. {10,10,10,5}

    Returns: 84006840

  8. {9,9,9,8}

    Returns: 4976840082

  9. {8,8,8,8,3}

    Returns: 26582018108280

  10. {1,2,3}

    Returns: 0

  11. {1,2,3,4}

    Returns: 10

  12. {1,2,3,4,5}

    Returns: 13002

  13. {5,4,3,2,1}

    Returns: 13002

  14. {9,8,7,6,5}

    Returns: 137659322668468

  15. {1,3,5,7,9}

    Returns: 20760

  16. {2,4,6,8,10}

    Returns: 88358422

  17. {10,10,10}

    Returns: 6

  18. {9,9,10}

    Returns: 2

  19. {4,5,7,3}

    Returns: 588

  20. {5, 3, 5, 10, 7 }

    Returns: 1063713424

  21. {7, 7, 7, 7, 7 }

    Returns: 1206522685040520

  22. {8, 6, 8, 6, 7 }

    Returns: 513401645862496

  23. {10, 8, 7, 5, 5 }

    Returns: 18573355047042

  24. {7, 7, 6, 7, 6 }

    Returns: 114463568371380

  25. {6, 7, 7, 7, 8 }

    Returns: 786192615679824

  26. {10, 10, 10, 5 }

    Returns: 84006840

  27. {5, 10, 7, 8, 5 }

    Returns: 18573355047042

  28. {5, 5, 5, 4, 4 }

    Returns: 3364126704

  29. {10, 10, 5, 6, 4 }

    Returns: 760943909564

  30. {6, 6, 6, 6, 6 }

    Returns: 6577334442600


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: