Statistics

Problem Statement for "CountTilings"

Problem Statement

Time limit: 5 seconds.


You have an R times C rectangle divided into unit squares.


You want to perform a sequence of two actions.

The first action is to remove some collection of individual unit squares. (All remaining squares are left in their original positions.

The second action is to perfectly tile all the remaining squares using horizontally and/or vertically placed 1x2 dominoes.


Consider all possible ways of correctly performing these two actions. Among them, count all possible ways to perform the first action. Return that count modulo 1,000,000,007.

Definition

Class:
CountTilings
Method:
count
Parameters:
int, int
Returns:
int
Method signature:
int count(int R, int C)
(be sure your method is public)

Notes

  • In a perfect tiling of a collection of squares each 1x2 domino tile covers two squares, and each square is covered by exactly one domino.

Constraints

  • R will be between 1 and 8, inclusive.
  • If R = 8, C will be between 1 and 200, inclusive.
  • If R = 7, C will be between 1 and 1,000, inclusive.
  • If R <= 6, C will be between 1 and 8,000, inclusive.

Examples

  1. 1

    1

    Returns: 1

    As your first action you must remove the only square. For your second action you are then left with an empty set of squares, and that can be perfectly tiled using an empty set of dominoes.

  2. 2

    3

    Returns: 18

    There are 18 valid ways to perform the first action. All of them are shown below, using 'x' for a square you remove and '.' for a square you keep. xxx xxx xx. x.x .xx ..x x.. xxx xxx xx. x.x .xx xxx xxx ..x x.. ..x .x. x.. x.. ..x xx. .xx ... ... ..x .x. x.. ..x x.. ... ... xx. .xx ... ... Note that for some of these there are multiple valid ways to perform the second action. That has no impact on our answer, each of the options shown above is only counted once.

  3. 1

    50

    Returns: 365010934

    For a 1xC strip we are essentially just tiling it with 1x1 and 1x2 tiles. The numbers of such tilings are clearly Fibonacci numbers. The exact number of tilings for C = 50 is F[51] = 20,365,011,074.

  4. 1

    2

    Returns: 2

  5. 1

    3

    Returns: 3

  6. 1

    4

    Returns: 5

  7. 1

    7

    Returns: 21

  8. 1

    12

    Returns: 233

  9. 2

    1

    Returns: 2

  10. 3

    1

    Returns: 3

  11. 4

    1

    Returns: 5

  12. 8

    1

    Returns: 34

  13. 2

    2

    Returns: 6

  14. 2

    4

    Returns: 54

  15. 2

    5

    Returns: 162

  16. 2

    6

    Returns: 486

  17. 2

    7

    Returns: 1458

  18. 2

    8

    Returns: 4374

  19. 2

    9

    Returns: 13122

  20. 2

    10

    Returns: 39366

  21. 2

    11

    Returns: 118098

  22. 2

    12

    Returns: 354294

  23. 2

    13

    Returns: 1062882

  24. 2

    14

    Returns: 3188646

  25. 3

    2

    Returns: 18

  26. 3

    3

    Returns: 98

  27. 3

    4

    Returns: 550

  28. 3

    5

    Returns: 3054

  29. 3

    6

    Returns: 17014

  30. 3

    7

    Returns: 94682

  31. 3

    8

    Returns: 527086

  32. 3

    9

    Returns: 2933902

  33. 4

    2

    Returns: 54

  34. 4

    3

    Returns: 550

  35. 4

    4

    Returns: 5700

  36. 4

    5

    Returns: 58830

  37. 4

    6

    Returns: 607752

  38. 4

    7

    Returns: 6276966

  39. 5

    2

    Returns: 162

  40. 5

    3

    Returns: 3054

  41. 5

    4

    Returns: 58830

  42. 5

    5

    Returns: 1125703

  43. 6

    2

    Returns: 486

  44. 6

    3

    Returns: 17014

  45. 6

    4

    Returns: 607752

  46. 7

    2

    Returns: 1458

  47. 7

    3

    Returns: 94682

  48. 7

    4

    Returns: 6276966

  49. 8

    2

    Returns: 4374

  50. 8

    3

    Returns: 527086

  51. 6

    198

    Returns: 757855121

  52. 3

    178

    Returns: 142373929

  53. 6

    140

    Returns: 400117503

  54. 7

    200

    Returns: 76820147

  55. 3

    196

    Returns: 798243119

  56. 5

    190

    Returns: 831501210

  57. 7

    166

    Returns: 300638278

  58. 8

    198

    Returns: 81721241

  59. 8

    195

    Returns: 748384129

  60. 3

    150

    Returns: 252047761

  61. 2

    197

    Returns: 176205388

  62. 1

    195

    Returns: 158879092

  63. 4

    103

    Returns: 235066220

  64. 2

    200

    Returns: 757545448

  65. 7

    196

    Returns: 672168915

  66. 6

    200

    Returns: 287744010

  67. 1

    155

    Returns: 453204199

  68. 7

    193

    Returns: 675016939

  69. 3

    198

    Returns: 143555643

  70. 1

    170

    Returns: 540401498

  71. 4

    200

    Returns: 834645531

  72. 8

    130

    Returns: 96665849

  73. 6

    172

    Returns: 234939633

  74. 1

    191

    Returns: 762791999

  75. 2

    132

    Returns: 436703975

  76. 8

    200

    Returns: 789118743

  77. 8

    156

    Returns: 492075730

  78. 1

    200

    Returns: 529309711

  79. 2

    199

    Returns: 585848485

  80. 5

    161

    Returns: 794729464

  81. 6

    190

    Returns: 722538700

  82. 4

    184

    Returns: 815465933

  83. 4

    190

    Returns: 801954016

  84. 4

    196

    Returns: 581747554

  85. 5

    191

    Returns: 835217659

  86. 5

    133

    Returns: 491290472

  87. 3

    200

    Returns: 97443836

  88. 5

    200

    Returns: 436376943

  89. 7

    130

    Returns: 135055965

  90. 2

    143

    Returns: 798517805

  91. 7

    972

    Returns: 420683059

  92. 4

    5043

    Returns: 585080251

  93. 1

    6514

    Returns: 996575932

  94. 5

    7982

    Returns: 997365554

  95. 5

    2942

    Returns: 437807021

  96. 6

    7837

    Returns: 540162958

  97. 6

    6815

    Returns: 715642674

  98. 4

    1885

    Returns: 580311472

  99. 5

    8000

    Returns: 977740233

  100. 1

    6

    Returns: 13

  101. 3

    4650

    Returns: 34160780

  102. 6

    7986

    Returns: 38067925

  103. 4

    7846

    Returns: 360877698

  104. 4

    5930

    Returns: 56403070

  105. 4

    5396

    Returns: 76377844

  106. 2

    273

    Returns: 351793935

  107. 5

    3066

    Returns: 169774566

  108. 1

    7843

    Returns: 65252484

  109. 7

    891

    Returns: 911324946

  110. 6

    7979

    Returns: 112786267

  111. 2

    4287

    Returns: 942399642

  112. 5

    7974

    Returns: 179726845

  113. 6

    8000

    Returns: 464509049

  114. 7

    860

    Returns: 676358534

  115. 5

    75

    Returns: 218811564

  116. 7

    1000

    Returns: 973101978

  117. 7

    954

    Returns: 524749248

  118. 3

    7723

    Returns: 197272297


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: