Statistics

Problem Statement for "KnightsOut"

Problem Statement

Mr. Purple is a very imaginative and creative person. In his spare time he invents different puzzles and games. Recently he has come up with a new puzzle called "Knights Out". Mr. Purple likes his new idea very much, but he is somewhat afraid that it may appear to be too easy or too hard. Therefore, Mr. Purple would like to know how many solutions these puzzles have before he presents the idea to puzzle-producing companies.

"Knights Out" is a one-player game played on a NxM rectangular board divided into 1x1 squares. Each square on the board can be white or black. Initially all the squares are white.

A knight is a chess piece that moves by simultaneously shifting one square horizontally and two squares vertically, or one square vertically and two squares horizontally. Two squares A and B on the board are called neighboring if it's possible to make a single knight's move to reach B from A.

In one move the player can choose a square on the board and simultaneously change colors of the chosen square and all its neighboring squares (white becomes black and vice versa). The game is finished when all the squares are colored black.

A sequence of moves is called a solution if it transforms the white board into a black one, and there's no cell which is chosen in more than one move. Note that when a cell is chosen, its neighbors which get changed do not also count as being "chosen" in that step. It's not hard to see that the order of moves doesn't matter, so any solution can be viewed as a set of moves. Two solutions are considered distinct if the corresponding sets are distinct. Return the number of distinct solutions modulo 123,456,789.

Definition

Class:
KnightsOut
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int N, int M)
(be sure your method is public)

Constraints

  • N and M will each be between 1 and 150, inclusive.

Examples

  1. 2

    3

    Returns: 4

    4 possible solutions are listed below ('X' means a square should be chosen and '.' means it shouldn't): XX. .X. XXX .XX XX. XXX .X. .XX

  2. 3

    3

    Returns: 1

    The only solution is to choose each square on the board.

  3. 7

    5

    Returns: 16

  4. 1

    1

    Returns: 1

  5. 150

    150

    Returns: 16

  6. 6

    6

    Returns: 16

  7. 8

    8

    Returns: 256

  8. 16

    16

    Returns: 4096

  9. 33

    33

    Returns: 16384

  10. 34

    34

    Returns: 21521878

  11. 69

    69

    Returns: 86087512

  12. 70

    70

    Returns: 41000473

  13. 118

    118

    Returns: 38723623

  14. 141

    141

    Returns: 23360683

  15. 142

    142

    Returns: 103002862

  16. 4

    2

    Returns: 16

  17. 4

    22

    Returns: 256

  18. 16

    6

    Returns: 4096

  19. 8

    34

    Returns: 65536

  20. 20

    10

    Returns: 1048576

  21. 12

    118

    Returns: 16777216

  22. 1

    2

    Returns: 1

  23. 3

    1

    Returns: 1

  24. 1

    150

    Returns: 1

  25. 149

    1

    Returns: 1

  26. 1

    134

    Returns: 1

  27. 123

    1

    Returns: 1

  28. 2

    2

    Returns: 1

  29. 5

    2

    Returns: 4

  30. 2

    6

    Returns: 1

  31. 7

    2

    Returns: 1

  32. 2

    8

    Returns: 1

  33. 150

    2

    Returns: 1

  34. 2

    149

    Returns: 4

  35. 148

    2

    Returns: 16

  36. 2

    147

    Returns: 4

  37. 146

    2

    Returns: 1

  38. 2

    145

    Returns: 1

  39. 123

    2

    Returns: 4

  40. 2

    134

    Returns: 1

  41. 3

    4

    Returns: 1

  42. 5

    3

    Returns: 4

  43. 6

    3

    Returns: 1

  44. 4

    4

    Returns: 1

  45. 4

    5

    Returns: 1

  46. 4

    6

    Returns: 16

  47. 6

    5

    Returns: 4

  48. 3

    150

    Returns: 1

  49. 150

    4

    Returns: 16

  50. 149

    5

    Returns: 1

  51. 6

    150

    Returns: 16

  52. 135

    136

    Returns: 4

  53. 136

    137

    Returns: 4

  54. 149

    149

    Returns: 256

  55. 148

    148

    Returns: 4096

  56. 149

    148

    Returns: 256

  57. 149

    150

    Returns: 1

  58. 148

    150

    Returns: 1

  59. 147

    148

    Returns: 256

  60. 147

    147

    Returns: 64

  61. 149

    147

    Returns: 64

  62. 150

    147

    Returns: 1

  63. 99

    107

    Returns: 1

  64. 142

    139

    Returns: 4

  65. 131

    105

    Returns: 4

  66. 141

    83

    Returns: 1

  67. 105

    149

    Returns: 1

  68. 108

    141

    Returns: 1

  69. 55

    83

    Returns: 16

  70. 108

    143

    Returns: 16

  71. 133

    10

    Returns: 1

  72. 121

    144

    Returns: 1

  73. 139

    141

    Returns: 4

  74. 145

    108

    Returns: 4

  75. 105

    99

    Returns: 1

  76. 147

    146

    Returns: 1

  77. 144

    143

    Returns: 1

  78. 139

    147

    Returns: 1

  79. 146

    25

    Returns: 1

  80. 52

    133

    Returns: 256

  81. 134

    61

    Returns: 4

  82. 138

    123

    Returns: 4

  83. 129

    87

    Returns: 1

  84. 73

    29

    Returns: 4

  85. 70

    129

    Returns: 16

  86. 97

    61

    Returns: 16

  87. 142

    115

    Returns: 64

  88. 69

    142

    Returns: 77502052


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: