The main effect of the topic:
An alternative set of experiments has been identified e={e1,e2,...,em}, and all the instruments needed to be used in the experiment are I={I1,I2 ... in}. The instrument to be used in experimental EJ is a subset of I rjíi. The cost of configuration instrumentation ik is USD ck. The experimental EJ sponsors have agreed to pay PJ dollars for the results of the experiment. Professor W's task is to find an effective algorithm for determining what experiments are to be carried out in a space flight and therefore which instruments will be allocated to maximize the net gain from space flight. Net income here is the difference between the total cost of all the proceeds from the experiment and the total costs of the equipment.
For a given experiment and instrument configuration, program to find the biggest net income test plan.
N,m<=50 :
Add a source point s, meeting point T,
s to all experiments to connect an edge of the price they can withstand as capacity
All instruments to t even a side of the price they need to pay as capacity
Each experiment is connected to the desired instrument with an infinity edge.
The problem is transformed into a model of the problem of the maximal right closed sub graph, which is then transformed into a minimal cut problem ①
Minimum cut equals maximum flow, so use network flow to solve
The instruments and experiments needed are the points in the S set of the smallest cut, that is, the set of vertices that are finally accessible from S.
The least cut method is to start from the source point, all the points can reach the point is the smallest cut of s set.
An understandable explanation of a passage to ①:
Since we are asking for the maximum yield, this benefit should be equal to ∑c[i] (experiment I was selected)-∑p[j] (instrument j is selected). To ensure maximum benefit, we should try to make ∑c[i] as big as possible, ∑p[j as small as possible. If the ∑c[i] is as large as possible, then ∑c[k] (experiment K is not selected) should be as small as possible. In other words, we should choose the smallest possible ∑c[k]+∑p[j], so as to maximize the benefits. and C[k], p[j] correspond to the arcs of the connections s and T of the network stream just constructed, and once the arcs are deleted, the entire network will be disconnected (this point can be contradiction proof). So we can naturally think of the smallest cut.
The problem is that the smallest cut in a network stream is asked.
Next, according to the minimum cut maximum flow theorem, we can replace the maximum flow.
I have a little understanding:
For this diagram, you have to make as much effort as you can to make the source point of the graph not go to the meeting point T.
If there is not a full stream on one side of the edge that is drawn from S, it means that this experiment can make money, at which point you have to cut the sum of the edges with the least price. Make the least cost, because at the end of the day, the cost of conversion can be found by the edge of the "s–> experiment"
This time the minimum is the smallest cut of the graph, according to the minimum cut is equal to the maximum flow, maximum flow
then total revenue-minimum cost = maximum gain code: strong>
var A:array [0..101,0..101] of Longint;
Q:array [0..10001] of Longint;
Rp:array [0..101] of Longint;
V:array [0..101] of Boolean;
Sum,ans,n,m,s,t:longint;
Procedure Init;
var i,j,x:longint;
Begin READLN (M,N);
sum:=0;
s:=0;
t:=n+m+1;
For I:=1 to M do begin read (x);
Sum:=sum+x;
A[s,i]:=x;
While not (EOLN) does begin read (x);
A[i,x+m]:=maxlongint Div 4;
End
End
For I:=1 to n do begin read (x);
A[i+m,t]:=x;
End
End
function min (aa,bb:longint): Longint;
Begin if Aa>bb then exit (BB);
Exit (AA);
End
function BFs (): boolean;
var i,k,head,tail:longint; Begin Fillchar (rp,sizeof (R)p), 255);
head:=0;
Tail:=1;
rp[s]:=0;
Q[1]:=s;
While Head<tail does Begin Inc (head);
K:=q[head];
For I:=s to T do if Rp[i]=-1 then if A[k,i]>0 then
Begin rp[i]:=rp[k]+1;
If I=t then exit (true);
Inc (tail);
Q[tail]:=i;
End
End
Exit (FALSE);
End
function Dfs (dep,cp:longint): Longint;
var i,j,k:longint;
Begin if Dep=t then exit (CP);
k:=0;
For I:=s to T do if a[dep,i]>0 then if rp[dep]+1=rp[i] then BEGIN
J:=dfs (I,min (cp-k,a[dep,i));
A[dep,i]:=a[dep,i]-j; A[i,dep]:=a[i,dep]+j;
K:=k+j;
If K=cp then exit (k);
End
If K=0 then rp[dep]:=-1;
Exit (k);
End
Procedure Dinic;
Begin ans:=0;
While BFS () do Ans:=ans+dfs (S,maxlongint);
End
Procedure find (X:longint);
var i:longint;
Begin V[x]:=true;
For I:=s to T does if a[x,i]>0 then if not (V[i]) then find (i);
End
procedure Print;
var i,j:longint;
Begin find (s);
For I:=1 to M do if v[i] then write (i, ');
Writeln;
For i:=m+1 to M+n do if v[i] then write (i-m, ' ");
Writeln;
Writeln (Sum-ans);
End
Begin init;
Dinic;
Print
End.