Description
Input
Output
Contains only an integer that represents the maximum energy income that can be obtained. Note that you can also choose not to do any attacks so that the energy income is 0.
Sample Input
3 2
10 0
20 0
-10 0
-5 1 0 0
100 1 2 1
100 0
Sample Output
25
HINT
In the sample, the plant p1,1 can attack position (0,0), P2, 0 can attack position (2,1).
A scheme for, first attack p1,1, p0,1, at this time can attack p0,0. The total energy gain is (-5) +20+10 = 25. Note that the location (2,1) is protected by plant p2,0, so it is not possible to attack any plant in line 2nd.
"Approximate data size"
About 20% of the data meet 1≤n, m≤5;
About 40% of the data meet 1≤n, m≤10;
About 100% of the data meets 1≤n≤20,1≤m≤30,-10000≤score≤10000.
For more information, see Hubertau "The application of the minimum cut model in the informatics competition" the maximum right-closing graph
But a little bit different, because some points can not be taken, so we first topology, the useful points to select, and then run the smallest cut
1 Const2maxn= A;3maxm= -;4inf=10000000;5 var6D,a,first,q:Array[0.. MAXN*MAXM] ofLongint;7Next,last:Array[0.. MAXN*MAXM*MAXN*MAXM] ofLongint;8MapArray[0.. MAXN*MAXM,0.. MAXN*MAXM] ofLongint;9 N,m,tot,sum,cnt:longint;Ten One functionCalc (i,j:longint): Longint; A begin -Exit (i*m+j+1); - End; the - procedureInsert (x,y:longint); - begin - Inc (TOT); +last[tot]:=y; -next[tot]:=First[x]; +first[x]:=tot; A Inc (D[y]); at End; - - procedureInit; - var - I,j,k,l,r,x,y:longint; - begin in read (n,m); - fori:=0 toN-1 Do to forj:=0 toM-1 Do + begin - Read (A[calc (I,J))); the read (k); * ifJ>0 ThenInsert (Calc (i,j), Calc (i,j-1)); $ forl:=1 toK DoPanax Notoginseng begin - read (x, y); the Insert (Calc (i,j), calc (x, y)); + End; A End; thel:=1; r:=0; + fori:=0 toN-1 Do - ifD[calc (i,m-1)]=0 Then $ begin $ Inc (R); -Q[r]:=calc (i,m-1); - End; the whileL<=r Do - beginWuyi ifA[q[l]]>0 ThenInc (Sum,a[q[l]); the ifA[q[l]]>0 ThenInc (map[0, Q[l]],a[q[l]]); - ifa[q[l]]<0 ThenInc (map[q[l],n*m+1],-A[q[l]]); Wui:=First[q[l]]; - whileI<>0 Do About begin $ Dec (d[last[i]]); Inc (Map[last[i],q[l]],inf) ; - ifd[last[i]]=0 Then - begin - Inc (R); Aq[r]:=Last[i]; + End; thei:=Next[i]; - End; $ Inc (L); the End; thecnt:=R; the End; the - var inDis,vh,his,pre:Array[0.. MAXN*MAXM] ofLongint; the Flow:longint; the About procedureSAP; the var the I,j,aug,min:longint; the Flag:boolean; + begin -vh[0]:=cnt+2; thei:=0; aug:=inf;Bayi whiledis[i]<n*m+2 Do the begin thehis[i]:=; -flag:=false; - forj:=0 ton*m+1 Do the if(map[i,j]>0) and(dis[i]=dis[j]+1) Then the begin theflag:=true; the ifAUG>MAP[I,J] Thenaug:=Map[i,j]; -pre[j]:=i; thei:=J; the ifi=n*m+1 Then the begin94 Inc (FLOW,AUG); the whileI<>0 Do the begin the Inc (MAP[I,PRE[I]],AUG);98 Dec (map[pre[i],i],aug); Abouti:=Pre[i]; - End;101aug:=inf;102 End;103 Break ;104 End; the ifFlag Thencontinue;106min:=n*m+1;107 forj:=0 ton*m+1 Do108 if(map[i,j]>0) and(dis[j]<min) Thenmin:=Dis[j];109 Dec (vh[dis[i]]); the ifvh[dis[i]]=0 ThenBreak ;111dis[i]:=min+1; theInc (vh[min+1]);113 ifI<>0 Then the begin thei:=Pre[i]; theaug:=His[i];117 End;118 End;119Writeln (sum-flow); - End;121 122 begin123 Init;124 SAP; the End.
View Code
1565: [NOI2009] Plants vs Zombies-Bzoj