And HDU 1565 is a problem, but the data strengthened, it seems that the contour line DP can not.
1#include <cstdio>2#include <cstring>3#include <queue>4#include <vector>5 #defineMAXN 25106 #defineOO 0x3f3f3f3f7 using namespacestd;8 9 structEdge {Ten intu, V, F; OneEdge (intUintVintf): U (U), V (v), F (f) {} A }; - structDinic { - intN, SRC, DST; theVector<edge>Edge; -vector<int>G[MAXN]; - intDEP[MAXN], CUR[MAXN]; - + voidInitintNintSrcintDST) { - This->n =N; + This->SRC =src; A This->DST =DST; at for(intu=1; u<=n; u++ ) - g[u].clear (); - edge.clear (); - } - voidAdd_edge (intUintVintf) { - G[u].push_back (Edge.size ()); in Edge.push_back (Edge (u,v,f)); - G[v].push_back (Edge.size ()); toEdge.push_back (Edge (V,u,0) ); + } - BOOLBFs () { thequeue<int>Qu; *memset (DEP,0,sizeof(DEP)); $ Qu.push (SRC);Panax NotoginsengDEP[SRC] =1; - while( !Qu.empty ()) { the intu=Qu.front (); + Qu.pop (); A for(intt=0; T<g[u].size (); t++ ) { theEdge &e =Edge[g[u][t]]; + if(E.F &&!)DEP[E.V]) { -DEP[E.V] = dep[e.u]+1; $ Qu.push (E.V); $ } - } - } the returnDEP[DST]; - }Wuyi intDfsintUinta) { the if(U==DST | | a==0)returnA; - intRemain=a, past=0, na; Wu for(int&t=cur[u]; T<g[u].size (); t++ ) { -Edge &e =Edge[g[u][t]]; AboutEdge &ve = edge[g[u][t]^1]; $ if(dep[e.v]==dep[e.u]+1&& e.f && (na=Dfs (E.v,min (REMAIN,E.F)))) { -Remain-=na; -Past + =na; -E.F-=na; AVe.f + =na; + if(!remain) Break; the } - } $ returnpast; the } the intMaxflow () { the intFlow =0; the while(BFS ()) { -memset (cur,0,sizeof(cur)); inFlow + =DFS (src,oo); the } the returnflow; About } the }; the the intN, M; + intidx[ -][ -], Id_clock; - intarr[ -][ -], sum; the intdi[4] = {0,0, +1, -1 };Bayi intdj[4] = { +1, -1,0,0 }; the dinic D; the - intMain () { - while(SCANF ("%d%d", &n, &m) = =2 ) { theId_clock =0; thesum =0; the for(intI=1; i<=n; i++ ) the for(intj=1; j<=m; J + + ) { -scanf"%d", &arr[i][j]); theSum + =Arr[i][j]; theIDX[I][J] = + +Id_clock; the }94D.init (id_clock+2, id_clock+1, id_clock+2 ); the for(intI=1; i<=n; i++ ) the for(intj=1; j<=m; J + + ) { the if((I+J) &1 ) {98 D.add_edge (D.SRC, Idx[i][j], arr[i][j]); About for(intD=0; d<4; d++ ) { - intNI = i+Di[d];101 intNJ = j+Dj[d];102 if(1<=ni&&ni<=n &&1<=nj&&nj<=m) {103 intU =Idx[i][j];104 intv =Idx[ni][nj]; the D.add_edge (U, V, oo);106 }107 }108}Else {109 D.add_edge (Idx[i][j], D.DST, arr[i][j]); the }111 } theprintf"%d\n", sum-D.maxflow ());113 } the}
View Code
Hdu 1569 min. cut