Pagini recente » Cod sursa (job #3120627) | Cod sursa (job #3177908) | Cod sursa (job #2979986) | Cod sursa (job #2138691) | Cod sursa (job #1132925)
//Problem pavare from Infoarena
#include <cmath>
#include <algorithm>
#include <fstream>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
ifstream fin("pavare.in");
ofstream fout("pavare.out");
const int INF = 1 << 30;
const int MAX_N = 151;
const int MAX_M = 16;
int N, M, K;
bool good[MAX_N][MAX_M];
int d[MAX_N][MAX_M][1 << MAX_M];
int main() {
fin >> N >> M >> K;
for (int i = 0, x, y; i < K; i += 1) {
fin >> x >> y;
good[x - 1][y - 1] = 1;
}
for (int i = 1; i < N; i += 1) {
for (int mask = 0; mask < (1 << M); mask += 1) {
if (mask & 1) {
d[i][0][mask] = d[i - 1][M - 1][mask ^ 1];
} else {
d[i][0][mask] = d[i - 1][M - 1][mask];
}
}
for (int j = 1; j < M; j += 1) {
bool bad = (not (good[i][j] || good[i - 1][j] || good[i][j - 1] || good[i - 1][j - 1]));
cerr << bad << endl;
for (int mask = 0; mask < (1 << M); mask += 1) {
if ((1 << j) & mask) {
cerr << "0 ";
d[i][j][mask] = d[i][j - 1][mask ^ (1 << j)];
} else {
d[i][j][mask] = d[i][j - 1][mask];
if (bad && !((1 << (j - 1)) & mask)) {
cerr << "2 ";
d[i][j][mask] = max(d[i][j][mask],
d[i][j - 2][mask ^ (1 << j) ^ (1 << (j - 1))] + 1);
} else {
cerr << "1 ";
}
}
cerr << i << ' ' << j << ' ' << mask << ' ' << d[i][j][mask] << endl;
// cerr << ((1 << j) & mask) << ' ' << ((1 << (j - 1)) & mask) << endl;
}
}
cerr << endl;
}
fout << d[N - 1][M - 1][0];
return 0;
}