# UVA-11082 Matrix decompressing (maximum flow with upper and lower bounds)

Source: Internet
Author: User

Topic Links:

Matrix decompressing

Test instructions

Give a matrix of each row and each column of the and, (given is the first row or column of the and);

The value of each element in the matrix is between 1 and 20 to find such a matrix;

Ideas:

Turn it into a two-point diagram, an arc is connected between each row and column, then a source point and a sink point are attached, the source point is connected to the row point, the sink point is connected to the column point, and the maximum value is, of course, the largest stream with the lower bound, which needs to be handled by 1, while the edges connected to the Yuanhui are processed; 1 is the answer;

AC Code:

`#include <bits/stdc++.h>/*#include <iostream> #include <queue> #include <cmath> #include <cstring> #include < algorithm> #include <cstdio>*/using namespacestd;#defineRiep (n) for (int i=1;i<=n;i++)#defineRIOP (n) for (int i=0;i<n;i++)#defineRJEP (n) for (int j=1;j<=n;j++)#defineRJOP (n) for (int j=0;j<n;j++)#defineMST (SS,B) memset (ss,b,sizeof (ss));typedefLong LongLL;ConstLL mod=1e9+7;Const DoublePi=acos (-1.0);Const intinf=0x3f3f3f3f;Const intn=1e5+ -;intn,m,a[ \$],b[ \$],cap[ \$][ \$],path[ \$],flow[ \$];queue<int>Qu;intBFS () {MST (path,-1); flow[0]=inf; path[0]=0; Qu.push (0);  while(!Qu.empty ()) {        intFr=Qu.front ();        Qu.pop ();  for(intI=1; i<=n+m+1; i++)        {            if(path[i]==-1&&Cap[fr][i]) {Flow[i]=min (Cap[fr][i],flow[fr]); Path[i]=fr;            Qu.push (i); }        }    }    if(path[n+m+1]==-1)return-1; returnflow[n+m+1];}voidMaxflow () {intNow,pre;  while(1)    {        inttemp=BFS (); if(temp==-1) Break; now=n+m+1;  while(now!=0) {Pre=Path[now]; Cap[pre][now]-=temp; Cap[now][pre]+=temp; now=Pre; }    }}intMain () {intT,case=1; scanf ("%d",&t);  while(case<=t) {MST (Cap,0); scanf ("%d%d",&n,&m); Riep (n) scanf ("%d",&A[i]); Riep (n) {cap[0][i]=a[i]-a[i-1]-m; } Riep (M) scanf ("%d",&B[i]); Riep (m) {cap[i+n][n+m+1]=b[i]-b[i-1]-N; }         for(intI=1; i<=n;i++)             for(intj=1; j<=m;j++) Cap[i][j+n]= +;        Maxflow (); printf ("Matrix%d\n", case++); Riep (n) {Rjep (M-1) printf ("%d", cap[j+n][i]+1); printf ("%d\n", cap[m+n][i]+1); } printf ("\ n"); }    return 0;}`

UVA-11082 Matrix decompressing (maximum flow with upper and lower bounds)

Related Keywords:

### 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.