Statistics

Problem Statement for "DengklekBuildingRoads"

Problem Statement

Mr. Dengklek lives in the Kingdom of Ducks, where humans and ducks live together in peace and harmony.

There are N duck houses in the kingdom, conveniently numbered 1 through N. Currently, there are no roads between the houses. The king assigned Mr. Dengklek to build exactly M bidirectional roads, each connecting a pair of houses.

The king imposed two rules on Mr. Dengklek:
  • Let A and B be two different houses. Mr. Dengklek may build roads connecting these two houses if and only if 0 < |A-B| <= K. After the road is built, both house number A and house number B are said to be incident to the road. For each such pair of houses Mr. Dengklek may build multiple roads, each connecting the two houses.
  • Each house must be incident to an even number of roads. (Zero is also an even number.)
You are given the ints N, M, and K. Return the number of different ways Mr. Dengklek can build the roads, modulo 1,000,000,007. Two ways are different if there are two houses that are connected by a different number of roads.

Definition

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

Notes

  • The houses are not required to be connected. There may be pairs of houses such that it is impossible to travel from one to another by only using the roads.
  • The roads are allowed to cross arbitrarily. (If two roads cross, the crossing is built using bridges, so that each road only connects the two houses at its ends.)

Constraints

  • N will be between 1 and 30, inclusive.
  • M will be between 0 and 30, inclusive.
  • K will be between 1 and 8, inclusive.

Examples

  1. 3

    4

    1

    Returns: 3

    These are the three ways to build the roads:

  2. 4

    3

    3

    Returns: 4

    These are the four ways to build the roads:

  3. 2

    1

    1

    Returns: 0

    It is impossible to make each house incident to an even number of roads if there is only one road.

  4. 5

    0

    3

    Returns: 1

  5. 10

    20

    5

    Returns: 26964424

  6. 30

    30

    8

    Returns: 201860393

  7. 30

    30

    7

    Returns: 145979048

  8. 30

    30

    6

    Returns: 177956313

  9. 30

    30

    5

    Returns: 244633725

  10. 30

    30

    4

    Returns: 457088350

  11. 30

    30

    3

    Returns: 488218396

  12. 30

    30

    2

    Returns: 36571349

  13. 30

    30

    1

    Returns: 532655639

  14. 2

    0

    1

    Returns: 1

  15. 2

    1

    1

    Returns: 0

  16. 2

    30

    1

    Returns: 1

  17. 4

    30

    3

    Returns: 41208

  18. 4

    30

    1

    Returns: 136

  19. 6

    30

    5

    Returns: 595145665

  20. 8

    30

    3

    Returns: 898450917

  21. 7

    8

    6

    Returns: 55041

  22. 16

    28

    1

    Returns: 40116600

  23. 30

    2

    2

    Returns: 57

  24. 30

    2

    1

    Returns: 29

  25. 10

    2

    5

    Returns: 35

  26. 25

    13

    7

    Returns: 309349042

  27. 30

    15

    4

    Returns: 543238700

  28. 27

    27

    6

    Returns: 69218107

  29. 3

    19

    6

    Returns: 45

  30. 1

    30

    8

    Returns: 0

  31. 4

    16

    7

    Returns: 2673

  32. 23

    28

    1

    Returns: 319959386

  33. 16

    18

    4

    Returns: 250757448

  34. 29

    29

    7

    Returns: 85065498

  35. 30

    27

    7

    Returns: 627690142

  36. 30

    2

    8

    Returns: 204


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: