Test instructions: There are now N elves, two sprite balls each M1 and M2, each sprite alone using the first sprite ball has the probability of pi is captured, the second sprite ball alone with the probability of the UI is captured, while using a (1-PI) * (1-ui) The probability of being captured. A sprite ball can only be used once for a genie, but you can use two sprite balls on an elf. The number of sprites expected to be obtained under the optimal strategy.
If an elf can not be used at the same time two elf ball, then it is an obvious cost flow building, point A is the first kind of Sprite ball, point B is the second kind of Sprite ball, the source point to a, a, a flow equal to the number of corresponding Sprite ball edge (cost 0), A, B respectively to each wizard with a flow of 1 The cost for the corresponding Pi/ui side, each sprite connected to a flow of 1 of the edge point to the meeting point, the limit can only use a sprite ball, run the maximum cost flow (here the maximum cost flow is equal to the maximum cost of the maximum flow, because the sprite ball with more than expected to capture the number of elves will not be reduced).
Now we need to consider the case of using two sprite balls at the same time, but it is not easy to connect the sprite to the edge of the sink +1, as this adds up to the fact that the two sprites are in effect, and the probability is pi*ui.
Then we think subtract part of the more, but also to ensure that only use a sprite ball without subtracting this part, then we from each wizard to the meeting point out two traffic to 1 of the edge, a fee of 0, a fee of-pi*ui, using the first Elf ball when the longest road must walk the cost of 0 side, When using the second sprite ball, you must go to the second edge to remove the repetition. Run the maximum cost stream.
Pit point: The cost of this problem is real, SPFA compared to the size of the time must use EPS, or will be stuck out of tle ....
#include <cstdio>#include<cstring>Const intmaxn=2005, maxm=20005;structedge{intTo,next,w;DoubleCost ;} LST[MAXM];intlen=0, FIRST[MAXN];voidAddedge (intAintBintWDoubleCost ) {lst[len].to=b;lst[len].next=first[a];lst[len].w=w;lst[len].cost=cost;first[a]=len++; Lst[len].to=a;lst[len].next=first[b];lst[len].w=0; lst[len].cost=-cost;first[b]=len++;}BOOLINQ[MAXN];intS,T,T,HEAD,TAIL,Q[MAXN],VIS[MAXN],PRT[MAXN];DoubleDIS[MAXN];BOOLSPFA () {head=tail=0; q[tail++]=s;inq[s]=true; Vis[s]=++t;dis[s]=0;p rt[s]=-1; while(head!=tail) { intx=q[head++];head%=maxn;inq[x]=false; for(intPT=FIRST[X];p t!=-1;p t=Lst[pt].next) { if(lst[pt].w==0)Continue; if(vis[lst[pt].to]!=t| | dis[x]+lst[pt].cost-dis[lst[pt].to]>1e-8){//This place is a pit of God ... Direct comparison size tle to death ...vis[lst[pt].to]=t;dis[lst[pt].to]=dis[x]+Lst[pt].cost; Prt[lst[pt].to]=pt; if(!Inq[lst[pt].to]) {Inq[lst[pt].to]=true; q[tail++]=lst[pt].to;tail%=MAXN; } } } } returnvis[t]==T;}DoubleMaxcost () {Doubleans=0; while(SPFA () &&dis[t]>0) {ans+=Dis[t]; for(intPt=prt[t];p t!=-1;p t=prt[lst[pt^1].to]) {LST[PT].W--;lst[pt^1].w++; } } returnans;}DoubleP[MAXN],U[MAXN];intMain () {memset (First,-1,sizeof(first)); intN,M1,M2;SCANF ("%d%d%d",&n,&m1,&m2); S=0; t=n+3; Addedge (S,n+1, M1,0); Addedge (s,n+2, M2,0); for(intI=1; i<=n;++i) scanf ("%LF", p+i); for(intI=1; i<=n;++i) scanf ("%LF", u+i); for(intI=1; i<=n;++i) {Addedge (n+1I1, P[i]); Addedge (n+2I1, U[i]); Addedge (I,t,1,0); Addedge (I,t,1,-p[i]*U[i]); } printf ("%.5f\n", Maxcost ()); return 0;}
codeforces739e Gosha is hunting