Statistics

Problem Statement for "ChristmasTree"

Problem Statement

You are decorating your Christmas tree. The tree has N levels, numbered 1 through N from top to bottom. You have a number of red, green and blue baubles, and you've decided to hang them in the following manner: On each level k, you will hang a row of exactly k baubles. Within each row, you will select the colors of the baubles such that there is an equal number of baubles of each color used in that level. For example, consider the following two trees:

      R                 R
    B   G             B   G 
  R   R   R         R   B   R
The tree on the left is correctly decorated. Each row contains an equal number of baubles for each color used. The tree on the right, however, is not correctly decorated because the third level contains an unequal number of red and blue baubles.

You are given an int N, the number of levels in the tree, and ints red, green and blue, representing the number of available baubles in each color. Return the number of distinct correct ways to decorate the tree. Two decorated trees are different if there is at least one position at which the two trees have a different colored bauble. If it is impossible to decorate the tree with the given baubles, return 0.

Definition

Class:
ChristmasTree
Method:
decorationWays
Parameters:
int, int, int, int
Returns:
long
Method signature:
long decorationWays(int N, int red, int green, int blue)
(be sure your method is public)

Constraints

  • N will be between 1 and 10, inclusive.
  • red will be between 0 and 50, inclusive.
  • green will be between 0 and 50, inclusive.
  • blue will be between 0 and 50, inclusive.

Examples

  1. 1

    1

    2

    0

    Returns: 2

  2. 1

    0

    0

    0

    Returns: 0

  3. 2

    1

    1

    1

    Returns: 6

    You can use any of the three colors for the top bauble, which always leaves you with two choices for the second level. Hence, there is a total of six different ways to decorate the tree: R R B G G B B B R G G R G G B R R B

  4. 2

    2

    1

    0

    Returns: 3

    If you put the green bauble on the top level, you must put both reds on the second level. On the other hand, if you put the red bauble on the top level, you have two different ways to decorate the second level (red-green or green-red). That makes a total of three ways.

  5. 2

    3

    0

    0

    Returns: 1

  6. 2

    0

    3

    0

    Returns: 1

  7. 2

    0

    0

    3

    Returns: 1

  8. 2

    3

    3

    3

    Returns: 27

  9. 2

    7

    1

    0

    Returns: 4

  10. 3

    7

    1

    0

    Returns: 4

  11. 3

    7

    1

    1

    Returns: 19

  12. 3

    7

    4

    3

    Returns: 211

  13. 3

    7

    7

    7

    Returns: 243

  14. 3

    2

    2

    1

    Returns: 0

    You have only five baubles, while six are needed to cover three levels.

  15. 3

    2

    2

    2

    Returns: 36

    The third level must either have three baubles of the same color or three baubles with different colors. Since you don't have three baubles of the same color, you must use three different colors for that level.

  16. 4

    0

    10

    0

    Returns: 1

  17. 4

    1

    10

    1

    Returns: 19

  18. 4

    1

    8

    1

    Returns: 12

  19. 4

    5

    8

    0

    Returns: 69

  20. 4

    5

    8

    5

    Returns: 4170

  21. 4

    10

    10

    10

    Returns: 5103

  22. 4

    5

    0

    5

    Returns: 18

  23. 4

    5

    1

    3

    Returns: 0

  24. 5

    7

    4

    4

    Returns: 258

  25. 5

    15

    0

    0

    Returns: 1

  26. 5

    14

    1

    0

    Returns: 3

  27. 5

    14

    1

    1

    Returns: 18

  28. 5

    4

    10

    1

    Returns: 141

  29. 5

    4

    10

    10

    Returns: 7010

  30. 6

    20

    20

    20

    Returns: 2342274

  31. 6

    20

    0

    20

    Returns: 5630

  32. 7

    24

    3

    1

    Returns: 153

  33. 7

    20

    3

    5

    Returns: 12667

  34. 8

    1

    15

    20

    Returns: 197121

  35. 8

    13

    15

    20

    Returns: 519710536

  36. 9

    13

    15

    20

    Returns: 145192863537

  37. 9

    23

    0

    22

    Returns: 87463

  38. 9

    23

    1

    22

    Returns: 795052

  39. 9

    1

    43

    1

    Returns: 12

  40. 9

    50

    50

    50

    Returns: 2518971350049

  41. 10

    50

    50

    50

    Returns: 1911899254684272

  42. 10

    50

    5

    0

    Returns: 661

  43. 10

    2

    3

    50

    Returns: 627

  44. 10

    3

    3

    49

    Returns: 3906

  45. 10

    0

    0

    50

    Returns: 0

  46. 10

    25

    15

    15

    Returns: 6125137522902

  47. 3

    4

    1

    1

    Returns: 12

  48. 1

    12

    12

    12

    Returns: 3

  49. 10

    50

    50

    50

    Returns: 1911899254684272

  50. 6

    50

    50

    50

    Returns: 2342277

  51. 10

    1

    1

    1

    Returns: 0

  52. 9

    49

    49

    49

    Returns: 2518971350049

  53. 2

    1

    1

    1

    Returns: 6

  54. 1

    1

    1

    1

    Returns: 3


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: