1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102
| H = 8
W = 10 board = [ [1, 1, 1, 1, 1, 1, 1, 1, 1, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 0, 0, 0, 0, 0, 0, 0, 0, 1], [1, 1, 1, 1, 1, 1, 1, 1, 1, 1] ]
cases = [ [[1, 0], [0, 1], [0, 0]], [[0, 1], [1, 1], [0, 0]], [[1, 0], [1, 1], [0, 0]], [[1, 0], [1, -1], [0, 0]] ]
def out_range(y, x): if (y < 0 or x < 0 or H <= y or W <= x): return True return False
def put(y, x, c): ret = True for point in c: _y = y + point[0] _x = x + point[1] if out_range(_y, _x): ret = False else: board[_y][_x] += 1 if board[_y][_x] > 1: ret = False
return ret
def get(y, x, c): for point in c: _y = y + point[0] _x = x + point[1] if out_range(_y, _x): continue else: board[_y][_x] -= 1
def solve(): fx = fy = None for i in range(H): for j in range(W): if board[i][j] == 0: fy = i fx = j break
if fx != None: break
if fx == None: return 1
ret = 0 for c in cases: if put(fy, fx, c): ret += solve() get(fy, fx, c)
return ret
print(solve())
|