UVA 11082 Matrix decompressing "Max Flow"

Source: Internet
Author: User

Only see the topic words ~ ~ How can not see it is the network flow of the topic said ~ ~ ~ ~

Building the map is amazing ~ ~

At first I did not understand---later looked at this article--

Http://www.cnblogs.com/AOQNRMGYXLMV/p/4280727.html

Establish source Point st = 0, Meeting point ed = r+c

Because the range of positive integers is 1 to 20, and the flow can be 0, so first subtract each number inside the matrix by 1, and then add 1 to the final output answer.

Think of each row as a node x, numbered 1 to R

Consider each column as a node y, numbered r+1 through R+c

St to x Edge, capacity Ai '-C

Y to Ed Edge, Volume bi '-R

X-to-y edge with a capacity of 19

Just use it again, dinic.

The traffic from node XI to YJ is the value after lattice (i,j)-1

The beginning of the sentence was very, very incomprehensible-------

Then I searched the puzzle.

Because the YJ traffic comes from each X

Similarly, the flow of Xi flows to each Y, so (i,j) the flow source of this lattice is XI

Probably like this picture.

1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <queue>6 using namespacestd;7 8 Const intMAXN =10005;9 Const intINF = (1<< -) -1;Ten  One structedge{ A     intv,next,c; - }E[MAXN]; -  the intst,ed,lev[maxn],first[maxn],now[maxn],ecnt; - intr,c; -  - voidinit () { +memset (first,-1,sizeof(first)); -ECNT =0; + } A  at voidAddedges (intUintVintc) { -E[ecnt].next =First[u]; -E[ECNT].V =v; -E[ECNT].C =C; -First[u] = ecnt++; -      inE[ecnt].next =First[v]; -E[ECNT].V =u; toE[ECNT].C =0; +FIRST[V] = ecnt++; - } the  * BOOLBFs () { $queue<int>Q;Panax Notoginseng      while(!q.empty ()) Q.pop (); - Q.push (ST); thememset (lev,-1,sizeof(Lev)); +LEV[ST] =0; A      while(!Q.empty ()) { the         intx =Q.front (); Q.pop (); +          for(inti = First[x];~i;i =E[i].next) { -             intv =e[i].v; $             if(Lev[v] <0&& e[i].c >0){ $LEV[V] = Lev[x] +1; - Q.push (v); -             } the         } -     }Wuyi     returnLev[ed]! =-1; the } -  Wu intDfsintPintMinf) { -     if(p = = Ed | | minf = =0)returnMinf; About      for(int&i = Now[p];~i;i =E[i].next) { $         intv =e[i].v; -         if(Lev[v] = = Lev[p] +1&& e[i].c >0){ -             intD =Dfs (V,min (e[i].c,minf)); -             if(D >0){ AE[I].C-=D; +e[i^1].C + =D; the                 returnD; -             } $         } the     } the     return 0; the } the  - intDinic () { in     intMax_flow =0, p1; the      while(BFS ()) { thememcpy (Now,first,sizeof(first)); About          while((P1 = dfs (st,inf)) >0) theMax_flow + =P1; the     } the     returnMax_flow; + } -  the intans[ -][ -];Bayi  the intMain () { the     intT; -scanf"%d",&T); -     intKase =0; the      while(t--){ thescanf"%d%d",&r,&c); the init (); theSt =0; ed = r+c+1; -          the         intLast =0, cur;  the          for(inti =1; I <= r;i++){ thescanf"%d",&cur);94Addedges (st,i,cur-last-c); theLast =cur; the         } the         98Last =0; About          for(inti =1; I <= c;i++){ -scanf"%d",&cur);101Addedges (i + r,ed,cur-last-R);102Last =cur;103         }104          the          for(inti =1; I <= r;i++)106              for(intj =1; J <= c;j++) addedges (I,j+r, +);107         108         intres =dinic ();109          the          for(intU =1; u <= r;u++){111              for(inti = First[u];~i;i =E[i].next) { the                 intv =e[i].v;113ANS[U][V-R] = +-e[i].c; the             } the         } the         117printf"Matrix%d\n",++Kase);118          for(inti =1; I <= r;i++){119printf"%d", ans[i][1] +1); -              for(intj =2; J <= c;j++)121printf"%d", Ans[i][j] +1);122printf"\ n");123         }124         if(T) puts (""); the     }126     return 0;127}
View Code

UVA 11082 Matrix decompressing "Max Flow"

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.