Statistics

Problem Statement for "FairTournament"

Problem Statement

Consider a tournament with n participants, numbered 1 to n in decreasing order by strength. The outcome of the tournament is a ranking of all the participants: participant p1 in first place (ranking 1), participant p2 in second place (ranking 2), ..., participant pn in last place (ranking n). It can be easily seen that p is a permutation.

An outcome of the tournament is called k-fair if every participant gets a ranking that differs from his number by at most k. In other words, p is a permutation where the following condition holds for all i: |i-pi|<=k.

Given an int n and an int k, return the number of different possible k-fair outcomes for a n-player tournament. The return value must be a String with no extra leading zeroes.

Definition

Class:
FairTournament
Method:
countPermutations
Parameters:
int, int
Returns:
String
Method signature:
String countPermutations(int n, int k)
(be sure your method is public)

Constraints

  • n will be between 1 and 100, inclusive.
  • k will be between 1 and 6, inclusive.

Examples

  1. 3

    1

    Returns: "3"

    Rankings "1,2,3", "2,1,3" and "1,3,2" are 1-fair, while "2,3,1", "3,1,2" and "3,2,1" are not.

  2. 3

    2

    Returns: "6"

  3. 10

    3

    Returns: "19708"

  4. 100

    1

    Returns: "573147844013817084101"

  5. 1

    1

    Returns: "1"

  6. 5

    2

    Returns: "31"

  7. 9

    3

    Returns: "6404"

  8. 12

    4

    Returns: "1396948"

  9. 14

    5

    Returns: "135025756"

  10. 1

    6

    Returns: "1"

  11. 2

    6

    Returns: "2"

  12. 3

    6

    Returns: "6"

  13. 4

    6

    Returns: "24"

  14. 5

    6

    Returns: "120"

  15. 6

    6

    Returns: "720"

  16. 20

    1

    Returns: "10946"

  17. 33

    2

    Returns: "634245200926"

  18. 42

    3

    Returns: "69850708085388667677"

  19. 57

    4

    Returns: "159128297041016435714751131714066"

  20. 60

    5

    Returns: "198899054347029676663136942820561016192"

  21. 64

    6

    Returns: "704724510370835968978398201517613241969210494"

  22. 77

    1

    Returns: "8944394323791464"

  23. 83

    2

    Returns: "1596437957527888762181476388934"

  24. 78

    3

    Returns: "21837383439504338719488921621840706409"

  25. 93

    4

    Returns: "111494812890123593989212189685194654756253116957177754"

  26. 99

    5

    Returns: "7488476460554583387809300269213525343844718913007616902164197555"

  27. 97

    6

    Returns: "439331534188737229355695791949863554660183606464421634807769978978048"

  28. 100

    6

    Returns: "63966642926037141928677083283801398106777787737963379360032740763763584"

  29. 1

    1

    Returns: "1"


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: