骑士放置
最大独立集
#include <bits/stdc++.h>
using namespace std;
#define IO ios::sync_with_stdio(false);cin.tie(0); cout.tie(0)
inline int lowbit(int x) { return x & (-x); }
#define ll long long
#define ull unsigned long long
#define pb push_back
#define PII pair<int, int>
#define x first
#define y second
#define inf 0x3f3f3f3f
const int N = 110;
int n, m, k;
PII match[N][N];
bool g[N][N], st[N][N];
int dx[8] = {-2, -1, 1, 2, 2, 1, -1, -2};
int dy[8] = {1, 2, 2, 1, -1, -2, -2, -1};
bool find(int x, int y) {
for (int i = 0; i < 8; ++i) {
int a = x + dx[i], b = y + dy[i];
if (a < 1 || a > n || b < 1 || b > m) continue;
if (g[a][b] || st[a][b]) continue;
st[a][b] = 1;
PII t = match[a][b];
if (t.x == 0 || find(t.x, t.y)) {
match[a][b] = {x, y};
return true;
}
}
return false;
}
int main() {
IO;
cin >> n >> m >> k;
for (int i = 0; i < k; ++i) {
int x, y;
cin >> x >> y;
g[x][y] = 1;
}
int res = 0;
for (int i = 1; i <= n; ++i)
for (int j = 1; j <= m; ++j) {
if (g[i][j] || (i + j ) % 2) continue;
memset(st, 0, sizeof st);
if (find(i, j)) res++;
}
cout << n * m - res - k << '\n';
return 0;
}