import pulp def f(n, m): if n * m % 4 != 0: print("No") return model = pulp.LpProblem("L", pulp.LpMaximize) vars = [] Ls = [ [(0, 0), (1, 0), (1, 1), (1, 2)], [(0, 2), (1, 0), (1, 1), (1, 2)], [(0, 0), (0, 1), (0, 2), (1, 2)], [(0, 0), (0, 1), (0, 2), (1, 0)], [(0, 0), (1, 0), (2, 0), (2, 1)], [(0, 0), (1, 0), (2, 0), (0, 1)], [(0, 1), (1, 1), (2, 1), (2, 0)], [(0, 1), (1, 1), (2, 1), (0, 0)], ] for i in range(n): for j in range(m): for t, dl in enumerate(Ls): if all(0 <= i + di < n and 0 <= j + dj < m for di, dj in dl): vars.append( ( pulp.LpVariable(f"var_{i}_{j}_{t}", 0, 1, pulp.LpInteger), [(i + di, j + dj) for di, dj in dl], ) ) for v1, l1 in vars: for v2, l2 in vars: if id(v1) == id(v2): continue tmp = l1 + l2 if len(set(tmp)) != len(tmp): model += v1 + v2 <= 1 model += pulp.lpSum(v for v, _ in vars) == n * m // 4 model.solve(pulp.PULP_CBC_CMD(msg=0)) if model.status != 1: print("No") return f(6, 6)