Statistics

Problem Statement for "ZombieRPGDice"

Problem Statement

This problem has a non-standard time limit: 4 seconds.

This problem is about a specific way of rolling the dice in one franchise of tabletop RPG games.

Whenever the player attempts a non-trivial action, the action is evaluated as follows:

  • The game master sets the target value T based on the player's skill.
  • The game master gives the player some 6-sided dice to roll. Each die is either positive or negative.
  • The player rolls all the dice.
  • As long as there is a positive and a negative die with the same value, a pair of such dice is removed from the roll.
  • At this point, if there is a positive die with value less than or equal to the target, the roll is a success, otherwise it is a failure.
  • Each negative die that was not removed counts as a point of stress for the player. In this problem the points of stress do not matter and can be ignored.

For example, suppose the player had the target T = 5 and rolled P = 4 positive and N = 6 negative dice, getting the values {3, 6, 3, 6} on the positive dice and the values {2, 3, 1, 6, 3, 3} on the negative dice. To evaluate this roll, we first remove several pairs of a positive and a negative die with the same value (value 3 twice and value 6 once). Once we do that, we now see {6} on the only remaining positive die and {2, 1, 3} on the three remaining negative dice. Thus, the roll is a failure and the player receives three points of stress.

You are given the target T, the number P of positive dice and the number N of negative dice. Calculate p: the probability that the roll will be a success. Return (p * 6P+N) modulo 1,000,000,007.

Definition

Class:
ZombieRPGDice
Method:
expectation
Parameters:
int, int, int
Returns:
int
Method signature:
int expectation(int T, int P, int N)
(be sure your method is public)

Notes

  • It should be obvious that the value (p * 6P+N) is always a non-negative integer, and thus the return value is well-defined.

Constraints

  • T will be between 1 and 6, inclusive.
  • P will be between 0 and 250, inclusive.
  • N will be between 0 and 250, inclusive.

Examples

  1. 5

    1

    0

    Returns: 5

    There is one positive die and no negative dice, the target is 5. The roll will be a success if we roll anything other than a six. The probability of success is p = 5/6, and thus the correct return value is p*6 = 5.

  2. 3

    0

    7

    Returns: 0

    With only negative dice there can be no success.

  3. 4

    1

    1

    Returns: 20

    In order to be successful, we need to roll 1, 2, 3, or 4 on the positive die, and we need the negative die to differ from the positive die. The probability that both things happen is p = (4/6) * (5/6) = 20/36.

  4. 6

    15

    0

    Returns: 184981286

    Remember to use modular arithmetic. The return value shown here is 6^15 modulo (10^9 + 7).

  5. 5

    4

    6

    Returns: 50489560

  6. 3

    0

    0

    Returns: 0

    No dice at all = no success.

  7. 6

    0

    0

    Returns: 0

  8. 5

    250

    250

    Returns: 491881721

  9. 4

    2

    2

    Returns: 948

  10. 3

    0

    3

    Returns: 0

  11. 3

    162

    221

    Returns: 499207927

  12. 4

    233

    232

    Returns: 66756861

  13. 6

    0

    0

    Returns: 0

  14. 1

    144

    125

    Returns: 416777524

  15. 1

    230

    243

    Returns: 60011691

  16. 6

    0

    2

    Returns: 0

  17. 1

    150

    25

    Returns: 979279195

  18. 5

    231

    242

    Returns: 189915290

  19. 6

    176

    235

    Returns: 514708494

  20. 1

    249

    243

    Returns: 635864704

  21. 2

    0

    1

    Returns: 0

  22. 1

    2

    0

    Returns: 11

  23. 4

    240

    231

    Returns: 915644597

  24. 3

    142

    13

    Returns: 857826015

  25. 5

    219

    146

    Returns: 362702228

  26. 2

    243

    240

    Returns: 942765671

  27. 5

    3

    2

    Returns: 7440

  28. 3

    10

    197

    Returns: 192831477

  29. 5

    0

    0

    Returns: 0

  30. 5

    38

    140

    Returns: 104428302

  31. 3

    138

    123

    Returns: 779317467

  32. 2

    182

    15

    Returns: 887711823

  33. 4

    230

    242

    Returns: 48244098

  34. 3

    242

    240

    Returns: 354949843

  35. 1

    0

    3

    Returns: 0

  36. 4

    243

    237

    Returns: 633730082

  37. 3

    3

    1

    Returns: 1053

  38. 2

    3

    0

    Returns: 152

  39. 5

    216

    194

    Returns: 973115335

  40. 4

    3

    0

    Returns: 208

  41. 3

    3

    3

    Returns: 31308

  42. 4

    244

    250

    Returns: 270793273

  43. 5

    248

    246

    Returns: 96937661

  44. 5

    1

    1

    Returns: 25

  45. 6

    2

    2

    Returns: 1230

  46. 6

    1

    0

    Returns: 6

  47. 4

    243

    247

    Returns: 349386185

  48. 5

    78

    61

    Returns: 164676146

  49. 6

    151

    153

    Returns: 240615830

  50. 1

    111

    207

    Returns: 115512375

  51. 1

    225

    133

    Returns: 933875682

  52. 1

    249

    235

    Returns: 420548791

  53. 2

    2

    3

    Returns: 2772

  54. 3

    240

    247

    Returns: 320096383

  55. 1

    246

    143

    Returns: 291685005

  56. 3

    233

    246

    Returns: 7169017

  57. 4

    2

    1

    Returns: 176

  58. 1

    1

    2

    Returns: 25

  59. 4

    246

    244

    Returns: 274521847

  60. 5

    241

    233

    Returns: 692632782

  61. 1

    200

    202

    Returns: 120592065

  62. 3

    0

    2

    Returns: 0

  63. 4

    128

    29

    Returns: 826480375

  64. 6

    0

    1

    Returns: 0

  65. 2

    235

    139

    Returns: 87450873

  66. 6

    201

    116

    Returns: 468479916

  67. 6

    117

    240

    Returns: 691994676

  68. 3

    42

    118

    Returns: 784666214

  69. 1

    77

    13

    Returns: 546480898

  70. 6

    242

    231

    Returns: 981271743

  71. 4

    239

    244

    Returns: 330601200

  72. 1

    239

    233

    Returns: 811796350

  73. 1

    231

    118

    Returns: 727057849

  74. 3

    232

    77

    Returns: 492411483

  75. 1

    249

    242

    Returns: 177092881

  76. 3

    231

    241

    Returns: 489624414

  77. 4

    247

    241

    Returns: 676638886

  78. 2

    0

    2

    Returns: 0

  79. 1

    2

    3

    Returns: 1450

  80. 5

    232

    245

    Returns: 822776580

  81. 5

    0

    3

    Returns: 0

  82. 5

    3

    1

    Returns: 1275

  83. 5

    133

    195

    Returns: 875804878

  84. 2

    248

    245

    Returns: 851364663

  85. 5

    238

    239

    Returns: 872361750

  86. 6

    238

    238

    Returns: 228541640

  87. 1

    105

    106

    Returns: 881419851

  88. 4

    235

    249

    Returns: 780370392

  89. 3

    200

    180

    Returns: 435014743

  90. 6

    3

    2

    Returns: 7776

  91. 6

    139

    175

    Returns: 397724472

  92. 5

    239

    243

    Returns: 138781127

  93. 6

    245

    245

    Returns: 848567055

  94. 4

    153

    35

    Returns: 151463058

  95. 2

    249

    235

    Returns: 170737774

  96. 6

    18

    44

    Returns: 92313642

  97. 1

    248

    130

    Returns: 598745258

  98. 4

    230

    249

    Returns: 136626190

  99. 4

    231

    237

    Returns: 406178718

  100. 2

    210

    173

    Returns: 423120385

  101. 2

    3

    1

    Returns: 816

  102. 4

    0

    1

    Returns: 0

  103. 5

    248

    249

    Returns: 78278933

  104. 3

    3

    2

    Returns: 5778

  105. 5

    229

    187

    Returns: 772173647

  106. 6

    2

    3

    Returns: 6780

  107. 6

    1

    3

    Returns: 750

  108. 1

    224

    159

    Returns: 676842199

  109. 1

    233

    246

    Returns: 613002070

  110. 2

    90

    203

    Returns: 338528239

  111. 6

    236

    250

    Returns: 814026446

  112. 5

    247

    235

    Returns: 187188108

  113. 4

    250

    70

    Returns: 616802367

  114. 2

    239

    236

    Returns: 929491965

  115. 1

    1

    1

    Returns: 5

  116. 6

    249

    244

    Returns: 908930434

  117. 2

    232

    247

    Returns: 974609994

  118. 2

    2

    2

    Returns: 538

  119. 4

    17

    184

    Returns: 890803942

  120. 4

    31

    5

    Returns: 836890315

  121. 3

    0

    1

    Returns: 0

  122. 5

    195

    69

    Returns: 197652347

  123. 6

    250

    250

    Returns: 404915918


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: