Statistics

Problem Statement for "NoRepeatPlaylist"

Problem Statement

Michael loves listening to music from his cell phone while travelling by train. He currently has N songs in his cell phone. During one trip he has the time to listen to P songs. So his cell phone creates a playlist of P (not necessarily different) songs according to the following rules:

  • Each song has to be played at least once.
  • At least M songs have to be played between any two occurrences of the same song. (This ensures that the playlist is not playing the same song too often.)

Michael wonders how many different playlists his cell phone can create. You are given the ints N, M, and P. Let X be the number of valid playlists. Since X can be too large, your method must compute and return the value (X modulo 1,000,000,007).

Definition

Class:
NoRepeatPlaylist
Method:
numPlaylists
Parameters:
int, int, int
Returns:
int
Method signature:
int numPlaylists(int N, int M, int P)
(be sure your method is public)

Notes

  • Two playlists A and B are different if for some i between 1 and P, inclusive, the i-th song in A is different from the i-th song in B.

Constraints

  • N will be between 1 and 100, inclusive.
  • M will be between 0 and N, inclusive.
  • P will be between N and 100, inclusive.

Examples

  1. 1

    0

    3

    Returns: 1

    You have only 1 song which can be played as often as you want. So the only valid playlist is: {song1, song1, song1}.

  2. 1

    1

    3

    Returns: 0

    Now is the same scenario as in Example 0, but the song cannot be played 2 times in a row. Thus there is no valid playlist.

  3. 2

    0

    3

    Returns: 6

    Now you have 2 songs and you can play them as often as you want. Just remember that playlists {song1, song1, song1} and {song2, song2, song2} are not valid, because each song must be played at least once.

  4. 4

    0

    4

    Returns: 24

    You have time to play each song exactly once. So there are 4! possible playlists.

  5. 2

    1

    4

    Returns: 2

    The only two possibilities are {song1, song2, song1, song2} and {song2, song1, song2, song1}.

  6. 50

    5

    100

    Returns: 222288991

  7. 1

    0

    1

    Returns: 1

  8. 1

    1

    1

    Returns: 1

  9. 1

    0

    2

    Returns: 1

  10. 1

    1

    2

    Returns: 0

  11. 2

    0

    2

    Returns: 2

  12. 2

    1

    2

    Returns: 2

  13. 2

    2

    2

    Returns: 2

  14. 1

    0

    3

    Returns: 1

  15. 1

    1

    3

    Returns: 0

  16. 2

    0

    3

    Returns: 6

  17. 2

    1

    3

    Returns: 2

  18. 2

    2

    3

    Returns: 0

  19. 3

    0

    3

    Returns: 6

  20. 3

    1

    3

    Returns: 6

  21. 3

    2

    3

    Returns: 6

  22. 3

    3

    3

    Returns: 6

  23. 1

    0

    4

    Returns: 1

  24. 1

    1

    4

    Returns: 0

  25. 2

    0

    4

    Returns: 14

  26. 2

    1

    4

    Returns: 2

  27. 2

    2

    4

    Returns: 0

  28. 3

    0

    4

    Returns: 36

  29. 3

    1

    4

    Returns: 18

  30. 3

    2

    4

    Returns: 6

  31. 3

    3

    4

    Returns: 0

  32. 4

    0

    4

    Returns: 24

  33. 4

    1

    4

    Returns: 24

  34. 4

    2

    4

    Returns: 24

  35. 4

    3

    4

    Returns: 24

  36. 4

    4

    4

    Returns: 24

  37. 47

    47

    47

    Returns: 846397273

  38. 47

    46

    47

    Returns: 846397273

  39. 47

    47

    48

    Returns: 0

  40. 1

    0

    100

    Returns: 1

  41. 1

    1

    100

    Returns: 0

  42. 2

    0

    100

    Returns: 976371283

  43. 2

    1

    100

    Returns: 2

  44. 2

    2

    100

    Returns: 0

  45. 3

    0

    100

    Returns: 956927880

  46. 3

    1

    100

    Returns: 964556918

  47. 3

    2

    100

    Returns: 6

  48. 3

    3

    100

    Returns: 0

  49. 100

    0

    100

    Returns: 437918130

  50. 100

    100

    100

    Returns: 437918130

  51. 42

    20

    100

    Returns: 917652623

  52. 35

    4

    100

    Returns: 241141251

  53. 70

    33

    100

    Returns: 113350320

  54. 79

    78

    100

    Returns: 472081547

  55. 63

    16

    100

    Returns: 791270589

  56. 6

    5

    100

    Returns: 720

  57. 82

    61

    100

    Returns: 443647325

  58. 62

    50

    100

    Returns: 362358782

  59. 96

    11

    100

    Returns: 22353827

  60. 28

    13

    100

    Returns: 491360085

  61. 92

    3

    100

    Returns: 635215935

  62. 3

    1

    100

    Returns: 964556918

  63. 14

    6

    93

    Returns: 137054740

  64. 16

    5

    17

    Returns: 122941672

  65. 31

    19

    48

    Returns: 654394566

  66. 37

    0

    39

    Returns: 834227218

  67. 52

    22

    68

    Returns: 35563645

  68. 14

    6

    95

    Returns: 282801414

  69. 20

    12

    23

    Returns: 353616274

  70. 62

    25

    65

    Returns: 762027972

  71. 11

    11

    54

    Returns: 0

  72. 38

    36

    45

    Returns: 601830705

  73. 60

    15

    100

    Returns: 228534218

  74. 99

    3

    100

    Returns: 989467997

  75. 37

    7

    97

    Returns: 945713644

  76. 50

    30

    100

    Returns: 226791857

  77. 53

    3

    100

    Returns: 177662748

  78. 50

    23

    81

    Returns: 885425071

  79. 49

    7

    100

    Returns: 437821697

  80. 5

    5

    5

    Returns: 120

  81. 80

    8

    100

    Returns: 467650474

  82. 100

    25

    100

    Returns: 437918130

  83. 64

    33

    100

    Returns: 910604984

  84. 40

    15

    100

    Returns: 553780149

  85. 25

    13

    60

    Returns: 23832333

  86. 88

    5

    100

    Returns: 638621416

  87. 100

    1

    100

    Returns: 437918130

  88. 50

    10

    100

    Returns: 663536800

  89. 10

    10

    100

    Returns: 0

  90. 100

    10

    100

    Returns: 437918130

  91. 99

    5

    100

    Returns: 53044368

  92. 50

    7

    100

    Returns: 363575434

  93. 20

    2

    100

    Returns: 545911587

  94. 60

    25

    100

    Returns: 145208404

  95. 13

    9

    39

    Returns: 997218499

  96. 50

    50

    50

    Returns: 318608048


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: