Statistics

Problem Statement for "ColorfulLineGraphsDiv2"

Problem Statement

Bob is going to create a graph with N nodes. The graph will be constructed in two steps. First, Bob will take N isolated vertices, label them 1 through N and color each of them using one of K colors. Then, Bob will add some directed edges to the graph. For each i between 2 and N, inclusive, Bob may choose a single value j < i such that the nodes i and j have different colors. If he does, he will add the edge from i to j to his graph. Note that Bob may choose not to add any edge from node i, even if there are some valid choices of j.

Two graphs are considered the same if they have the same node colors and the same set of edges.

You are given the ints N and K. Compute and return the number of different graphs Bob may construct, modulo 1,000,000,007.

Definition

Class:
ColorfulLineGraphsDiv2
Method:
countWays
Parameters:
int, int
Returns:
int
Method signature:
int countWays(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 3, inclusive.

Examples

  1. 3

    2

    Returns: 24

    The 24 different graphs are shown below. In each picture, the vertices have labels 1, 2, 3 from the left to the right.

  2. 15

    2

    Returns: 789741546

  3. 100

    1

    Returns: 1

  4. 1

    3

    Returns: 3

  5. 100

    3

    Returns: 492594064

  6. 16

    3

    Returns: 434231843

  7. 22

    3

    Returns: 589570488

  8. 46

    3

    Returns: 265705562

  9. 93

    3

    Returns: 157695640

  10. 90

    2

    Returns: 166267694

  11. 51

    2

    Returns: 948537388

  12. 89

    2

    Returns: 749079870

  13. 62

    3

    Returns: 231620408

  14. 99

    3

    Returns: 873097489

  15. 49

    3

    Returns: 196932377

  16. 26

    3

    Returns: 568243825

  17. 59

    2

    Returns: 16340084

  18. 19

    2

    Returns: 146326063

  19. 95

    3

    Returns: 654868516

  20. 91

    3

    Returns: 550228583

  21. 12

    3

    Returns: 853525290

  22. 24

    3

    Returns: 780824365

  23. 76

    2

    Returns: 661063309

  24. 10

    3

    Returns: 749310484

  25. 73

    3

    Returns: 632284981

  26. 16

    3

    Returns: 434231843

  27. 22

    3

    Returns: 589570488

  28. 46

    3

    Returns: 265705562

  29. 93

    3

    Returns: 157695640

  30. 90

    2

    Returns: 166267694

  31. 51

    2

    Returns: 948537388

  32. 89

    2

    Returns: 749079870

  33. 62

    3

    Returns: 231620408

  34. 99

    3

    Returns: 873097489

  35. 49

    3

    Returns: 196932377

  36. 26

    3

    Returns: 568243825

  37. 59

    2

    Returns: 16340084

  38. 19

    2

    Returns: 146326063

  39. 95

    3

    Returns: 654868516

  40. 91

    3

    Returns: 550228583

  41. 12

    3

    Returns: 853525290

  42. 24

    3

    Returns: 780824365

  43. 76

    2

    Returns: 661063309

  44. 10

    3

    Returns: 749310484

  45. 73

    3

    Returns: 632284981


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: