Statistics

Problem Statement for "DengklekPaintingSquares"

Problem Statement

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

One day, the queen of the kingdom challenged Mr. Dengklek with a perplexing puzzle: she gave Mr. Dengklek an N × M board made of wood that consists of N*M squares. She then asked Mr. Dengklek to paint the squares according to these rules:

  • Each square must be either colored or empty.
  • Each colored square must have an even number of adjacent colored squares. Two squares are adjacent if they share a side.
For example, here is one valid solution for N=4, M=7:



In the above image, black squares denote empty squares and brown squares denote colored squares.

Of course, finding one solution to the puzzle is easy: we do not color anything. Instead, the queen asked Mr. Dengklek a much harder question: to count all valid solutions of the puzzle. Help Mr. Dengklek count the solutions and return the result modulo 1,000,000,007. Two solutions are different if there is a square that is colored in one solution and not colored in the other solution.

Definition

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

Constraints

  • N will be between 1 and 100, inclusive.
  • M will be between 1 and 8, inclusive.

Examples

  1. 1

    1

    Returns: 2

    Either Mr. Dengklek colors the square, or he does not. Both choices produce a valid solution.

  2. 2

    2

    Returns: 8

    Here are the 8 valid solutions:

  3. 1

    3

    Returns: 5

  4. 47

    7

    Returns: 944149920

  5. 1

    2

    Returns: 3

  6. 1

    4

    Returns: 8

  7. 1

    5

    Returns: 13

  8. 1

    6

    Returns: 21

  9. 1

    7

    Returns: 34

  10. 1

    8

    Returns: 55

  11. 3

    5

    Returns: 1067

  12. 4

    2

    Returns: 48

  13. 6

    7

    Returns: 142860055

  14. 7

    6

    Returns: 142860055

  15. 10

    6

    Returns: 852065842

  16. 10

    7

    Returns: 133047026

  17. 12

    4

    Returns: 217922751

  18. 12

    6

    Returns: 551648439

  19. 12

    7

    Returns: 509252402

  20. 15

    4

    Returns: 867152507

  21. 16

    8

    Returns: 559575281

  22. 17

    4

    Returns: 504929571

  23. 20

    3

    Returns: 133418092

  24. 21

    6

    Returns: 154558076

  25. 23

    8

    Returns: 238358301

  26. 25

    1

    Returns: 196418

  27. 25

    6

    Returns: 417472647

  28. 31

    1

    Returns: 3524578

  29. 32

    8

    Returns: 452099666

  30. 33

    2

    Returns: 434804009

  31. 33

    4

    Returns: 360549211

  32. 34

    7

    Returns: 892665396

  33. 36

    5

    Returns: 117112746

  34. 36

    7

    Returns: 665050769

  35. 36

    8

    Returns: 778391605

  36. 37

    3

    Returns: 22962921

  37. 38

    1

    Returns: 102334155

  38. 40

    2

    Returns: 696374975

  39. 41

    5

    Returns: 278606644

  40. 44

    2

    Returns: 746383206

  41. 45

    2

    Returns: 772345493

  42. 45

    3

    Returns: 814257636

  43. 47

    2

    Returns: 759037600

  44. 47

    6

    Returns: 388356121

  45. 48

    3

    Returns: 100797928

  46. 49

    3

    Returns: 796812565

  47. 49

    8

    Returns: 490790721

  48. 51

    3

    Returns: 806147414

  49. 56

    5

    Returns: 359935014

  50. 57

    2

    Returns: 422144489

  51. 57

    7

    Returns: 305868052

  52. 58

    3

    Returns: 919543957

  53. 64

    3

    Returns: 726998433

  54. 71

    1

    Returns: 527403788

  55. 75

    3

    Returns: 45508041

  56. 75

    5

    Returns: 697209289

  57. 77

    2

    Returns: 985695704

  58. 77

    3

    Returns: 458872362

  59. 77

    4

    Returns: 689857849

  60. 81

    1

    Returns: 400391533

  61. 81

    8

    Returns: 63610655

  62. 86

    1

    Returns: 665487541

  63. 86

    3

    Returns: 126082288

  64. 87

    7

    Returns: 589627493

  65. 88

    8

    Returns: 330398667

  66. 89

    6

    Returns: 643421135

  67. 90

    2

    Returns: 497304262

  68. 91

    4

    Returns: 726399354

  69. 91

    7

    Returns: 352147883

  70. 93

    5

    Returns: 368736803

  71. 93

    7

    Returns: 897180692

  72. 95

    4

    Returns: 662160581

  73. 98

    2

    Returns: 166674494

  74. 98

    8

    Returns: 536977998

  75. 99

    7

    Returns: 551738264

  76. 100

    1

    Returns: 470199269

  77. 100

    2

    Returns: 398139603

  78. 100

    3

    Returns: 76803773

  79. 100

    4

    Returns: 393669896

  80. 100

    5

    Returns: 804089593

  81. 100

    6

    Returns: 545306804

  82. 100

    7

    Returns: 124439073

  83. 100

    8

    Returns: 636302453

  84. 99

    8

    Returns: 857844889


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: