Statistics

Problem Statement for "KingdomAndCities"

Problem Statement

King Dengklek is the first king of the Kingdom of Ducks. The kingdom consists of N cities, conveniently numbered 0 through N-1. The first M cities (i.e., cities 0 through M-1) are restricted cities.

Initially, there are no roads in the kingdom, so no two cities are connected. King Dengklek wants to connect the cities using exactly K bidirectional roads, such that:

  • There is at most one road connecting each pair of cities.
  • No road connects a city to itself.
  • Each restricted city is connected to exactly two other cities.
  • For each pair of cities, there is at least one path (i.e., a sequence of consecutive roads) connecting them.

You are given the ints N, M, and K. Return the number of different ways King Dengklek can build the roads, modulo 1,000,000,007. Two ways are different if there is a pair of cities that is connected in one way but not connected in the other way.

Definition

Class:
KingdomAndCities
Method:
howMany
Parameters:
int, int, int
Returns:
int
Method signature:
int howMany(int N, int M, int K)
(be sure your method is public)

Constraints

  • N will be between 1 and 50, inclusive.
  • M will be between 0 and 2, inclusive.
  • M will be less than or equal to N.
  • K will be between 1 and 50, inclusive.

Examples

  1. 3

    0

    3

    Returns: 1

    Here is the only possible way.

  2. 4

    1

    4

    Returns: 9

    Here are the nine possible ways. The restricted city (city 0) is colored blue.

  3. 5

    2

    11

    Returns: 0

    There are too many roads to build.

  4. 5

    0

    8

    Returns: 45

  5. 10

    2

    20

    Returns: 150810825

  6. 1

    0

    1

    Returns: 0

  7. 1

    1

    1

    Returns: 0

  8. 2

    0

    1

    Returns: 1

  9. 2

    2

    2

    Returns: 0

  10. 2

    1

    1

    Returns: 0

  11. 5

    2

    3

    Returns: 0

  12. 5

    0

    3

    Returns: 0

  13. 6

    1

    4

    Returns: 0

  14. 6

    2

    4

    Returns: 0

  15. 6

    0

    4

    Returns: 0

  16. 16

    0

    49

    Returns: 48360829

  17. 49

    1

    29

    Returns: 0

  18. 25

    1

    33

    Returns: 506402538

  19. 8

    1

    8

    Returns: 578907

  20. 4

    2

    34

    Returns: 0

  21. 28

    0

    4

    Returns: 0

  22. 29

    0

    13

    Returns: 0

  23. 11

    0

    31

    Returns: 856255304

  24. 14

    0

    1

    Returns: 0

  25. 31

    1

    35

    Returns: 639226707

  26. 10

    2

    42

    Returns: 0

  27. 8

    2

    46

    Returns: 0

  28. 39

    0

    19

    Returns: 0

  29. 23

    2

    29

    Returns: 200458943

  30. 30

    2

    35

    Returns: 409602685

  31. 14

    0

    6

    Returns: 0

  32. 19

    1

    46

    Returns: 905919826

  33. 33

    1

    8

    Returns: 0

  34. 16

    0

    33

    Returns: 368947806

  35. 16

    1

    3

    Returns: 0

  36. 2

    1

    40

    Returns: 0

  37. 43

    2

    25

    Returns: 0

  38. 41

    1

    35

    Returns: 0

  39. 11

    0

    3

    Returns: 0

  40. 39

    0

    27

    Returns: 0

  41. 26

    2

    26

    Returns: 85272996

  42. 33

    2

    6

    Returns: 0

  43. 28

    0

    46

    Returns: 828756516

  44. 35

    2

    1

    Returns: 0

  45. 17

    1

    38

    Returns: 591679493

  46. 22

    1

    35

    Returns: 483487378

  47. 11

    0

    41

    Returns: 547303434

  48. 36

    2

    35

    Returns: 170513612

  49. 44

    0

    38

    Returns: 0

  50. 35

    2

    9

    Returns: 0

  51. 41

    2

    13

    Returns: 0

  52. 27

    1

    36

    Returns: 827423461

  53. 7

    2

    30

    Returns: 0

  54. 38

    2

    37

    Returns: 362211780

  55. 13

    1

    28

    Returns: 471304464

  56. 19

    0

    41

    Returns: 319153854

  57. 21

    1

    31

    Returns: 536604856

  58. 11

    2

    23

    Returns: 719296228

  59. 50

    0

    50

    Returns: 921061336

  60. 50

    1

    50

    Returns: 261563447

  61. 50

    2

    50

    Returns: 654698051


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: