Count blocks in a 2D grid
Python 2, 208 184 169 167 163 bytes

w,h=input()
def f(x):global g;o=g;g&amp;=~2**x;o&gt;g&gt;[x/w==(x+s)/w&lt;f(x+s)or-1&lt;x/w+s&lt;h&lt;f(x+s*w)for s in[-1,1]]
n=i=1&lt;&lt;w*h
while i:g=i=i-1;f(len(bin(g))-3);n-=g&gt;0
print~-n