Node Capacity: Break it up and write it.
---------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define CHK (x, y) (x >= 0 && x < R && y >= 0 && y < C)const int MAXN = 10000;const int MAXM = 2900;int H[MAXN], CNT[MAXN];int X[MAXM][MAXM], Y[MAXM][MAXM];int R, C, D, V, S, T, N;Char S[MAXM];struct Edge {int to, cap;Edge *next, *rev;} e[1000000], *pt = E, *HEAD[MAXN], *P[MAXN], *CUR[MAXN];inline void Add (int u, int v, int w) {pt->to = v; pt->cap = w; pt->next = Head[u]; Head[u] = pt++;}inline void Addedge (int u, int v, int w) {Add (U, V, W); Add (V, u, 0);Head[u]->rev = head[v];Head[v]->rev = Head[u];}void Init () {V = N = 0;scanf ("%d%d%d", &r, &c, &d);memset (x,-1, sizeof x);for (int i = 0; i < R; i++) {scanf ("%s", s);For (int j = 0; J < C; J + +) if (S[j] > ' 0 ') {X[i][j] = v++;Y[i][j] = v++;Addedge (X[i][j], y[i][j], S[j]-' 0 ');}}S = v++; T = v++;for (int i = 0; i < R; i++)For (int j = 0; J < C; J + +) if (~x[i][j])for (int d = 1; d <= D; d++)for (int k = 0; k <= D; k++) {int x = i + k, y = j + d-k;if (chk (x, y) && ~x[x][y]) Addedge (Y[i][j], x[x][y], MAXN);x = i-k, y = j-d + k;if (chk (x, y) && ~x[x][y]) Addedge (Y[i][j], x[x][y], MAXN);x = i + k, y = j-d + k;if (chk (x, y) && ~x[x][y]) Addedge (Y[i][j], x[x][y], MAXN);x = i-k, y = j + d-k;if (chk (x, y) && ~x[x][y]) Addedge (Y[i][j], x[x][y], MAXN);}for (int i = 0; i < R; i++) {scanf ("%s", s);For (int j = 0; J < C; J + +) {if (~x[i][j] && (i < D | | J < D | | i + d >= R | | j + d >= C) Addedge (Y[i][j], T, MAXN);if (s[j]! = '. ') Addedge (S, x[i][j], 1), n++;}}}void Solve () {memset (CNT, 0, sizeof CNT);memset (h, 0, sizeof h);cnt[0] = V;for (int i = 0; i < V; i++) cur[i] = Head[i];int Flow = 0; edge* e;for (int x = S, A = MAXN; H[s] < V;) {For (e = cur[x]; e; e = e->next)if (h[e->to] + 1 = = H[x] && e->cap) break;if (e) {P[e->to] = cur[x] = e;a = min (A, e->cap);if ((x = e->to) = = = T) {For (; x! = S; x = p[x]->rev->to) {P[x]->cap-= A;P[x]->rev->cap + = A;}Flow + = A;A = MAXN;}} else {if (!--Cnt[h[x]]) break;h[x] = V;For (e = head[x]; e = e->next) if (H[e->to] + 1 < h[x] && e->cap) {h[x] = h[e->to] + 1;cur[x] = e;}cnt[h[x]]++;if (x! = S) x = p[x]->rev->to;}}printf ("%d\n", N-flow);}int main () {Init ();Solve ();return 0;}
---------------------------------------------------------------
Bzoj 1066: [SCOI2007] Lizard (Max stream)