Statistics

Problem Statement for "RoundTable"

Problem Statement

There are countA representatives of a company A and countB representatives of a company B that are having a meeting at a round table. There are chairs chairs around the table and they want to sit down in such a way that no representative of company A is sitting closer than minDistance to a representative of company B (minDistance=1 means any seating is allowed, minDistance=2 means there must be at least one empty chair between representatives of different companies, etc.).

Return the number of ways that such a seating arrangement is possible. Two seating arrangements are different if at least one person is sitting in different chairs in the two arrangements (i.e., include in the count all possible rotations of each seating arrangement). Note also that two different representatives of the same company are to be treated as different persons, see example 5.

Definition

Class:
RoundTable
Method:
arrangements
Parameters:
int, int, int, int
Returns:
long
Method signature:
long arrangements(int countA, int countB, int chairs, int minDistance)
(be sure your method is public)

Notes

  • The return value will fit in a 64 bit signed int.
  • The input values are not guaranteed to allow a valid seating arrangement; if there is no seating arrangement that satisfies the input, return 0.

Constraints

  • countA and countB will each be between 1 and 5, inclusive.
  • chairs will be between 1 and 50, inclusive.
  • minDistance will be between 1 and 50, inclusive.

Examples

  1. 1

    1

    10

    1

    Returns: 90

    Each company sends one representative. The first one can sit in any of the 10 chairs, the second one in any of the remaining 9 chairs (since minDistance=1 he may sit arbitrarily close to the other one). So there are a total of 10 * 9 = 90 arrangements.

  2. 1

    1

    10

    2

    Returns: 70

    The same as example 0, but now the second one can not sit next to the first one, so only 7 chairs remain that he can choose from. This gives a total of 10 * 7 = 70 arrangements.

  3. 1

    2

    7

    3

    Returns: 14

    Company A sends one representative, who sits down in one of the 7 possible chairs. Since minDistance=3, two chairs next to him at each side must remain empty. This leaves only 2 chairs that the 2 representatives from company B have to share (2 possible combinations for which one takes which of the two chairs). This gives a total of 7 * 2 = 14 arrangements.

  4. 5

    3

    7

    1

    Returns: 0

    There are not enough chairs (5 + 3 = 8 representatives in total, but only 7 chairs).

  5. 5

    3

    11

    3

    Returns: 0

    Now there would be enough chairs, but since minDistance=3, we have to keep 2 chairs empty between the groups at each side, thus requiring at least 5 + 3 + 2 + 2 = 12 chairs.

  6. 2

    1

    3

    1

    Returns: 6

    Note that the two representatives of company A are treated as different persons, so there are a total of 3! = 6 possibilities to assign the three representatives to the three available chairs.

  7. 2

    3

    20

    4

    Returns: 180000

  8. 1

    1

    50

    1

    Returns: 2450

  9. 1

    1

    50

    25

    Returns: 50

  10. 1

    1

    50

    26

    Returns: 0

  11. 1

    1

    50

    50

    Returns: 0

  12. 1

    1

    49

    24

    Returns: 98

  13. 1

    1

    49

    25

    Returns: 0

  14. 5

    5

    50

    1

    Returns: 37276043023296000

  15. 5

    5

    12

    2

    Returns: 172800

  16. 5

    5

    11

    2

    Returns: 0

  17. 5

    5

    10

    1

    Returns: 3628800

  18. 5

    5

    9

    1

    Returns: 0

  19. 5

    5

    50

    21

    Returns: 720000

  20. 5

    5

    50

    22

    Returns: 0

  21. 5

    5

    50

    50

    Returns: 0

  22. 5

    5

    50

    2

    Returns: 11997198325008000

  23. 1

    5

    50

    23

    Returns: 6000

  24. 5

    1

    50

    23

    Returns: 6000

  25. 4

    5

    9

    1

    Returns: 362880

  26. 4

    5

    10

    2

    Returns: 0

  27. 4

    5

    11

    2

    Returns: 31680

  28. 2

    2

    4

    1

    Returns: 24

  29. 2

    2

    49

    23

    Returns: 784

  30. 2

    2

    49

    24

    Returns: 0

  31. 5

    2

    40

    17

    Returns: 67200

  32. 2

    5

    40

    18

    Returns: 0

  33. 3

    4

    45

    6

    Returns: 11350983600

  34. 3

    2

    8

    3

    Returns: 0

  35. 3

    5

    1

    1

    Returns: 0

  36. 2

    3

    43

    13

    Returns: 1578960

  37. 1

    5

    13

    2

    Returns: 393120

  38. 5

    3

    8

    2

    Returns: 0

  39. 5

    1

    47

    12

    Returns: 239722560

  40. 4

    4

    28

    9

    Returns: 5322240

  41. 4

    1

    37

    15

    Returns: 62160

  42. 3

    5

    23

    5

    Returns: 56833920

  43. 5

    2

    9

    2

    Returns: 2160

  44. 1

    2

    36

    11

    Returns: 7560

  45. 4

    4

    41

    2

    Returns: 1586171662848

  46. 2

    5

    13

    5

    Returns: 0

  47. 1

    5

    48

    4

    Returns: 4316532480

  48. 4

    5

    13

    3

    Returns: 37440

  49. 5

    5

    44

    10

    Returns: 1294428960000

  50. 5

    5

    22

    3

    Returns: 9517305600

  51. 1

    2

    44

    18

    Returns: 3168

  52. 4

    1

    40

    15

    Returns: 316800

  53. 4

    4

    35

    10

    Returns: 230630400

  54. 5

    5

    29

    14

    Returns: 0

  55. 3

    4

    16

    6

    Returns: 0

  56. 2

    3

    15

    4

    Returns: 12600

  57. 4

    4

    1

    1

    Returns: 0

  58. 5

    5

    37

    8

    Returns: 265025376000

  59. 3

    2

    47

    10

    Returns: 11666340

  60. 5

    2

    39

    11

    Returns: 173759040

  61. 1

    3

    10

    2

    Returns: 2100

  62. 4

    4

    11

    2

    Returns: 50688

  63. 2

    3

    20

    4

    Returns: 180000

  64. 5

    5

    50

    1

    Returns: 37276043023296000

  65. 1

    1

    50

    2

    Returns: 2350

  66. 5

    5

    50

    10

    Returns: 14519372400000

  67. 5

    5

    50

    2

    Returns: 11997198325008000

  68. 5

    5

    50

    19

    Returns: 514800000

  69. 5

    5

    50

    29

    Returns: 0

  70. 4

    5

    50

    7

    Returns: 6495147648000

  71. 5

    5

    50

    4

    Returns: 1302668806032000

  72. 5

    5

    50

    5

    Returns: 492115179744000

  73. 5

    5

    50

    3

    Returns: 3843379077120000

  74. 5

    5

    50

    21

    Returns: 720000

  75. 5

    5

    50

    15

    Returns: 211629600000

  76. 5

    5

    50

    50

    Returns: 0

  77. 5

    5

    20

    30

    Returns: 0


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: