Guest User

Untitled

a guest
Jul 17th, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.96 KB | None | 0 0
  1. 0 1 0 0
  2. 0 0 1 0
  3. 0 0 0 1
  4. 1 0 0 0
  5.  
  6. new_grid[i][j] is dependent on
  7. i) old_grid[i][j],
  8. ii) old_grid[i][j+1],
  9. iii) old_grid[i+1][j]
  10. iv) old_grid[i+1][j+1]
  11.  
  12. If exactly one of the above values are 1, then new_grid[i][j] will be 1, else 0.
  13.  
  14. 1 1
  15. 0 0
  16.  
  17. 1 0 1
  18. 0 0 0
  19. 0 0 0
  20.  
  21. 1 0 1
  22. 0 0 0
  23. 1 1 1
  24.  
  25. newGrid: 0 1 0
  26. 0 0 0
  27.  
  28. oldGrid 1: _ 0 1 _
  29. _ 0 0 _
  30. _ _ _ _
  31.  
  32. oldGrid 2: _ 1 0 _
  33. _ 0 0 _
  34. _ _ _ _
  35.  
  36. oldGrid 3: _ 0 0 _
  37. _ 1 0 _
  38. _ _ _ _
  39.  
  40. oldGrid 4: _ 0 0 _
  41. _ 0 1 _
  42. _ _ _ _
  43.  
  44. newGrid: 1 1 0
  45. 0 0 0
  46.  
  47. oldGrid 1: 1 0 _ _
  48. 0 0 _ _
  49. _ _ _ _
  50.  
  51. oldGrid 2: 0 1 _ _
  52. 0 0 _ _
  53. _ _ _ _
  54.  
  55. oldGrid 3: 0 0 _ _
  56. 1 0 _ _
  57. _ _ _ _
  58.  
  59. oldGrid 4: 0 0 _ _
  60. 0 1 _ _
  61. _ _ _ _
  62.  
  63. oldGrid 5: _ 1 0 _
  64. _ 0 0 _
  65. _ _ _ _
  66.  
  67. oldGrid 6: _ 0 1 _
  68. _ 0 0 _
  69. _ _ _ _
  70.  
  71. oldGrid 7: _ 0 0 _
  72. _ 1 0 _
  73. _ _ _ _
  74.  
  75. oldGrid 8: _ 0 0 _
  76. _ 0 1 _
  77. _ _ _ _
  78.  
  79. oldGrid 1.1: 1 0 1 _
  80. 0 0 0 _
  81. _ _ _ _
  82.  
  83. numberOfSolutions = numberOf1s * 4 * 2^(oldGridSize-4) - overlappingSolutionsCount
  84. numberOfOverlappingSolutions * 2^(oldGridSize-4-overlapAreaSize)
  85.  
  86. function countOverlappingSolutions(newGrid: an MxN matrix) {
  87. result = 0
  88. oldGridSize = (M+1) * (N+1)
  89. for each pair of 1s in the newGrid:
  90. let manhattanDistance = manhattan distance between the 1s in the pair
  91. let overlapAreaSize = 0
  92.  
  93. if the 1s are in the same row or column
  94. if manhattanDistance == 1:
  95. overlapSize = 2
  96. else if manhattanDistance == 2
  97. overlapAreaSize = 1
  98.  
  99. result += 2^(oldGridSize -4 -overlapAreaSize)
  100.  
  101. return result
  102. }
  103.  
  104. let newGrid be a MxN matrix
  105. let numberOf1s = number of 1s in newGrid
  106. let oldGridSize = (M+1) * (N+1)
  107.  
  108. result = numberOf1s * 4 * 2^(oldGridSize - 4) - countOverlappingSolutions(newGrid)
Add Comment
Please, Sign In to add comment