额。是单整点集。一开始没看到。。
还算好做,树形dp。
/** * Problem:POJ1192 * Author:Shun Yao * Time:2013.5.20 * Result:Accepted * Memo:DP */ #include <cstring> #include <cstdlib> #include <cstdio> long abs(long x) { return x < 0 ? -x : x; } const long Maxn = 1005; long n, ans, now, f[Maxn]; char visited[Maxn]; class pnode { public: long x, y, c; pnode() {} ~pnode() {} } p[Maxn]; class gnode { public: long v; gnode *next; gnode() {} ~gnode() {} gnode(long V, gnode *ne):v(V), next(ne) {} } *g[Maxn]; void add(long x, long y) { g[x] = new gnode(y, g[x]); g[y] = new gnode(x, g[y]); } void DP(long x) { visited[x] = 1; f[x] = p[x].c; for (gnode *e = g[x]; e; e = e->next) { if (!visited[e->v]) { DP(e->v); if (f[e->v] > 0) f[x] += f[e->v]; } } if (now < f[x]) now = f[x]; } int main() { static long i, j; freopen("poj1192.in", "r", stdin); freopen("poj1192.out", "w", stdout); scanf("%ld", &n); for (i = 1; i <= n; ++i) { g[i] = 0; scanf("%ld%ld%ld", &p[i].x, &p[i].y, &p[i].c); for (j = 1; j < i; ++j) if (abs(p[i].x - p[j].x) + abs(p[i].y - p[j].y) == 1) add(i, j); } memset(visited, 0, sizeof visited); for (i = 1; i <= n; ++i) if (!visited[i]) { now = 0; DP(i); ans += now; } printf("%ld", ans); fclose(stdin); fclose(stdout); return 0; }