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
| #include <bits/stdc++.h> #define STC static #define lowbit(x) (x & -x) #define dis(a, b) (abs(a.x - b.x) + abs(a.y - b.y)) using namespace std; const int N = 14 + 5, M = 100 + 5, NN = (1 << 14) + 5; int n, m, nn, ans = 0; struct Door { int x, y; } d[N]; struct Task { int x, y, t; bool operator < (const Task& task) const { return t < task.t; } } ta[M]; int td[NN][N], tt[NN][M]; int f[NN][M], g[NN][M], lg2[NN]; int main() { scanf("%d %d", &n, &m), nn = 1 << n; for (int i = 1; i <= n; ++i) scanf("%d %d", &d[i].x, &d[i].y); for (int i = 1; i <= m; ++i) scanf("%d %d %d", &ta[i].x, &ta[i].y, &ta[i].t); sort(ta + 1, ta + 1 + m); memset(td, 0x3f, sizeof td), memset(tt, 0x3f, sizeof tt); lg2[1] = 0; for (int i = 2; i <= nn; ++i) lg2[i] = lg2[i >> 1] + 1; for (int s = 1, j = lowbit(s); s < nn; ++s, j = lowbit(s)) { for (int i = 1; i <= n; ++i) td[s][i] = min(td[s ^ j][i], dis(d[lg2[j] + 1], d[i])); for (int i = 1; i <= m; ++i) tt[s][i] = min(tt[s ^ j][i], dis(d[lg2[j] + 1], ta[i])); } memset(f, 0xcf, sizeof f), memset(g, 0x3f, sizeof g); for (int i = 1; i <= n; ++i) g[1 << (i - 1)][0] = 0; for (int i = 1; i <= m; ++i) f[0][i] = 1; for (int s = 0; s < nn; ++s) for (int i = 0; i <= m; ++i) { for (int j = 1; j <= n; ++j) if (!((s >> (j - 1)) & 1)) g[s ^ (1 << (j - 1))][i] = min(g[s][i] + td[s][j], g[s ^ (1 << (j - 1))][i]); for (int j = 1; j <= m; ++j) if (g[s][i] + tt[s][j] <= ta[j].t) f[s][j] = max(i + 1, f[s][j]); for (int j = 1; j <= n; ++j) if (!((s >> (j - 1)) & 1) && f[s][i] > 0) g[s ^ (1 << (j - 1))][f[s][i]] = min(ta[i].t + min(td[s][j], dis(ta[i], d[j])), g[s ^ (1 << (j - 1))][f[s][i]]); for (int j = i + 1; j <= m; ++j) if (ta[i].t + min(dis(ta[i], ta[j]), tt[s][j]) <= ta[j].t) f[s][j] = max(f[s][j], f[s][i] + 1); ans = max(ans, f[s][i]); } printf("%d\n", ans); return 0; }
|