Hdu 1569 min. cut

Source: Internet
Author: User

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-&GT;SRC =src; A          This-&GT;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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.