Statistics

Problem Statement for "Gangsters"

Problem Statement

There are people gangsters in Gangsterville, and that small town definitely isn't big enough for all of them. Therefore they decided to organize a shootout. May only the best survive!

The gangsters arranged themselves in a circle. For simplicity we'll number them from 1 to people along the circle. Each gangster is pointing his gun at the next gangster in the circle. (I.e., for each valid i gangster number i is aiming at gangster number i+1, and the last gangster is aiming at gangster 1.)

In order to make the gunfight more spectator-friendly, the gangsters have decided that they will shoot sequentially. Before the gunfight they will choose one of the people! possible orders uniformly at random. Then, they will shoot their guns in the chosen order. (Obviously, gangsters who have already been shot do nothing when it's their turn.) Each gangster always hits their target.

Calculate the number of orderings for which the number of gangsters who will survive is exactly alive. Return the answer modulo 10^9+7.

Definition

Class:
Gangsters
Method:
countOrderings
Parameters:
int, int
Returns:
int
Method signature:
int countOrderings(int people, int alive)
(be sure your method is public)

Constraints

  • people will be between 3 and 150, inclusive.
  • alive will be between 0 and people, inclusive.

Examples

  1. 4

    2

    Returns: 12

    We have four gangsters numbered 1, 2, 3, and 4 along the circle. There are 4! = 24 possible orders in which they will shoot. First consider the six permutations in which gangster 1 shoots first: 1 2 3 4 1 2 4 3 1 3 2 4 1 3 4 2 1 4 2 3 1 4 3 2 In each of these six settings gangster 1 will shoot gangster 2. As gangster 2 will not shoot, gangster 3 is guaranteed to survive. In three of these six setting gangster 3 will shoot before gangster 4. In these three scenarios the survivors will be gangsters 1 and 3. In the other three scenarios gangster 3 will be the only survivor. We can then make similar reasoning for the remaining cases. In total there are 12 orderings with exactly two survivors (and another 12 with just one survivor).

  2. 3

    1

    Returns: 6

    There are six possible shooting orders for three gangsters. For all of them only one gangster will remain alive.

  3. 3

    0

    Returns: 0

    It is not possible that no one survives.

  4. 9

    3

    Returns: 203616

  5. 3

    2

    Returns: 0

  6. 3

    3

    Returns: 0

  7. 4

    0

    Returns: 0

  8. 4

    1

    Returns: 12

  9. 4

    3

    Returns: 0

  10. 4

    4

    Returns: 0

  11. 5

    1

    Returns: 20

  12. 5

    2

    Returns: 100

  13. 5

    3

    Returns: 0

  14. 6

    1

    Returns: 30

  15. 6

    2

    Returns: 510

  16. 6

    3

    Returns: 180

  17. 6

    4

    Returns: 0

  18. 150

    0

    Returns: 0

  19. 150

    1

    Returns: 22350

  20. 150

    74

    Returns: 449712960

  21. 150

    75

    Returns: 298327036

  22. 150

    150

    Returns: 0

  23. 44

    11

    Returns: 625464479

  24. 132

    14

    Returns: 246806497

  25. 48

    8

    Returns: 221386274

  26. 63

    13

    Returns: 448176929

  27. 74

    32

    Returns: 483436209

  28. 141

    22

    Returns: 621265395

  29. 137

    41

    Returns: 249561047

  30. 74

    3

    Returns: 885520416

  31. 73

    19

    Returns: 785941369

  32. 13

    3

    Returns: 165614592

  33. 88

    9

    Returns: 659224951

  34. 34

    6

    Returns: 926765467

  35. 55

    27

    Returns: 647720112

  36. 15

    4

    Returns: 698999714

  37. 96

    32

    Returns: 432385400

  38. 56

    15

    Returns: 277163265

  39. 53

    13

    Returns: 344727290

  40. 32

    8

    Returns: 443989692

  41. 128

    25

    Returns: 641032416

  42. 104

    51

    Returns: 721782805

  43. 118

    19

    Returns: 430336012

  44. 34

    7

    Returns: 506841146

  45. 23

    2

    Returns: 81010100

  46. 49

    25

    Returns: 0

  47. 108

    49

    Returns: 890690503

  48. 14

    6

    Returns: 956730625

  49. 132

    3

    Returns: 351568247

  50. 47

    10

    Returns: 33620122

  51. 129

    46

    Returns: 679602399

  52. 43

    8

    Returns: 86487190

  53. 58

    19

    Returns: 600000269

  54. 123

    36

    Returns: 806730792

  55. 45

    14

    Returns: 118549538

  56. 111

    26

    Returns: 194493840

  57. 8

    2

    Returns: 7224

  58. 31

    8

    Returns: 652379459

  59. 115

    32

    Returns: 808357575

  60. 37

    14

    Returns: 363746661

  61. 73

    17

    Returns: 520857457

  62. 32

    7

    Returns: 208964088

  63. 48

    1

    Returns: 2256

  64. 73

    18

    Returns: 794039711

  65. 33

    7

    Returns: 457687856

  66. 22

    11

    Returns: 36721329

  67. 81

    4

    Returns: 800646368

  68. 43

    9

    Returns: 504122179

  69. 103

    49

    Returns: 310994297

  70. 48

    5

    Returns: 260712075

  71. 39

    7

    Returns: 534355308

  72. 119

    60

    Returns: 0

  73. 30

    11

    Returns: 256729948

  74. 113

    32

    Returns: 111601008

  75. 114

    52

    Returns: 945354954

  76. 82

    39

    Returns: 301919122

  77. 96

    13

    Returns: 496107025

  78. 65

    24

    Returns: 449026526

  79. 60

    21

    Returns: 639262763

  80. 81

    40

    Returns: 221940159

  81. 16

    2

    Returns: 23593200

  82. 13

    2

    Returns: 1437852

  83. 107

    16

    Returns: 838941142

  84. 122

    4

    Returns: 712265217

  85. 40

    8

    Returns: 950068627

  86. 108

    53

    Returns: 470613649

  87. 40

    14

    Returns: 307400679

  88. 89

    39

    Returns: 270414044

  89. 140

    55

    Returns: 385434859

  90. 69

    32

    Returns: 19555135

  91. 87

    10

    Returns: 749168526

  92. 100

    20

    Returns: 834358364

  93. 19

    9

    Returns: 77589857

  94. 109

    41

    Returns: 108333060

  95. 11

    4

    Returns: 23682120

  96. 131

    60

    Returns: 80839208

  97. 83

    20

    Returns: 163282721

  98. 27

    6

    Returns: 123919043

  99. 30

    6

    Returns: 650286915

  100. 150

    50

    Returns: 351696986


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: