Originally wanted to write water problem .... The results have been so long! It's just a define with a little extra parenthesis!
Binary graph maximum point right independent set ... Dye it in black and white, and then build the diagram:
S--Black_node, White_node-T, traffic is the point right. Then Black_node-White_node (two points with a common edge), the flow is +oo, then answer =∑w (i) (i∈v)-Maxflow
-------------------------------------------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream> #define REP (i, n) for (int i = 0; i < n; ++i)#define CLR (x, C) memset (x, C, sizeof (x))#define ID (x, y) ((x) * n + y + 1)using namespace std;const int inf = 0X7FFFFFFF;const int MAXN = +;struct Edge {int to, cap;Edge *next, *rev;} e[maxn << 3], *pt = E, *head[MAXN];inline void Add_edge (int u, int v, int w) {pt-to = V;pt, Cap = w;pt-Next = head[u];head[U] = pt++;pt-to = u;pt-caps = 0;pt-Next = head[v];head[v] = pt++;head[u], rev = head[V];Head[v], rev = head[U];}int h[MAXN], cnt[MAXN], S, T, N;Edge *cur[MAXN], *p[MAXN];int Maxflow () {CLR (h, 0), CLR (CNT, 0);cnt[0] = N;Rep (i, N) cur[i] = head[i];int flow = 0, A = inf;edge* E;for (int x = s; h[s] < N;) {For (E = cur[x]; e; e = e = next)if (h[e-to] + 1 = = h[x] && e caps) break;if (e) {a = min (A, e-cap);p[e-to] = cur[x] = e;if ((x = e) = = = T) {For (; x! = S; x = p[x], rev-to) {p[x], caps-= A;p[X]-rev, Cap + A; }flow + = A;A = inf;}} else {if (!--cnt[h[X]]) break;h[x] = N;For (E = head[x]; e; e = e = next)if (Cap && h[E, to] + 1 < h[x]) {h[x] = h[E to] + 1;cur[x] = e; }cnt[h[x]]++;if (x! = S) x = p[x], rev to;}}return flow;}int main () {freopen ("test.in", "R", stdin);CLR (head, 0);int ans = 0, n;cin >> N;S = 0, t = n * n + 1, n = t + 1;Rep (i, N)Rep (j, N) {int W;scanf ("%d", &w);ans + = w;if ((i + j) & 1) {Add_edge (S, id (i, j), W);if (i) Add_edge (ID (i, j), ID (i-1, j), INF);if (j) Add_edge (ID (i, j), ID (i, j-1), INF);if (i + 1 < n) Add_edge (ID (i, j), ID (i + 1, j), INF);if (j + 1 < N) Add_edge (ID (i, j), ID (i, j + 1), INF);} else Add_edge (ID (i, j), T, W); }cout << ans-maxflow () << "\ n";return 0;}
-------------------------------------------------------------------------------------------------
1475: Check number of squares Time Limit:5 Sec Memory Limit:MB
Submit:616 Solved:323
[Submit] [Status] [Discuss] Description in a n*n square, each lattice has a positive integer. Take out a number of the number, so that any two out of the lattice has no common side, and the sum of the number taken out as large as possible. Input the first row a number n; (n<=30) the next n rows each row n number describes a matrix output only one number, that is, the largest and the sample Input 2
1 2
3 5
Sample Output 6
HINT
Source
Bzoj 1475: Tick count (Network stream)