Statistics

Problem Statement for "TreeSpreading"

Problem Statement

A farmer is planting a line of trees across the front of his house. He has four different kinds of trees he would like to plant. However, for aesthetic reasons, he does not want two of the same type of tree next to each other. Beyond that, any arrangement of trees is considered acceptable.

You are given ints a, b, c, and d, indicating how many of each type of tree the farmer is going to plant. You are to return a long indicating the number of acceptable ways in which the trees can be ordered.

Definition

Class:
TreeSpreading
Method:
countArrangements
Parameters:
int, int, int, int
Returns:
long
Method signature:
long countArrangements(int a, int b, int c, int d)
(be sure your method is public)

Notes

  • Each tree of a given type is identical to others of the same type, thus swapping the positions of two of the same type of tree does not consitute a new arrangement.

Constraints

  • a, b, c, and d will be between 0 and 10, inclusive.

Examples

  1. 1

    1

    0

    0

    Returns: 2

    There are only two trees to place, and they can go in either order.

  2. 2

    2

    0

    0

    Returns: 2

    There are two possible arrangements: ABAB or BABA. Any others have two identical trees adjacent to one another.

  3. 1

    1

    1

    1

    Returns: 24

    Since all four trees are different, they can be arranged in any order, so the answer is 4!.

  4. 3

    2

    1

    1

    Returns: 96

  5. 10

    10

    10

    10

    Returns: 174702663548149248

  6. 5

    1

    1

    1

    Returns: 0

  7. 9

    10

    8

    7

    Returns: 173887297986990

  8. 1

    2

    3

    4

    Returns: 1074

  9. 5

    6

    7

    8

    Returns: 33170046582

  10. 9

    10

    10

    8

    Returns: 5475644741386140

  11. 3

    4

    7

    9

    Returns: 71903316

  12. 7

    8

    9

    10

    Returns: 173887297986990

  13. 9

    7

    5

    4

    Returns: 2552333100

  14. 10

    9

    7

    5

    Returns: 2161729439448

  15. 10

    8

    7

    1

    Returns: 78434892

  16. 9

    6

    3

    0

    Returns: 504

  17. 0

    0

    0

    0

    Returns: 1

  18. 10

    10

    10

    10

    Returns: 174702663548149248

  19. 0

    0

    0

    0

    Returns: 1


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: