P1355--8-2 space flight plan issues
Time limit: 1000MS
Memory Limit: 131072KB
Description
Professor W is planning a series of space flights for the National Space Center. Every space flight can make a series of commercial experiments to gain profits. A selection of experimental set E={e1,e2,...,em} has been identified, and the set of all instruments required for these experiments to be used I={i1,i2, ... in}. The instrument that the experimental EJ needs to use is a subset of I rjíi. The cost of configuring the instrument IK is ck USD. The sponsors of the experiment EJ have agreed to pay PJ dollars for the results of the experiment. Prof W's task is to find an effective algorithm to determine which experiments are to be carried out in a space flight and which instruments will be used to make space flight the largest net yield. The net income here is the difference between the full amount of revenue obtained from the experiment and the total cost of the equipment being configured.
For a given experiment and instrument configuration, the program is programmed to find the maximum net yield. (N,M<50)
Input Format
The 1th line has 2 positive integers m and N. M is the number of experiments, and N is the number of instruments. The next M-line, each row is an experimental data. The first number of sponsors agreed to pay the cost of the experiment, followed by the number of instruments used in the experiment. The number of n in the last line is the cost of configuring each instrument.
Output Format
Line 1th is the experiment number; line 2nd is the instrument number; the last line is net income.
Sample Input
2 310 1 225 2 35 6 7
Sample Output
1 21 2 317
Hint"Puzzle + Spit Groove"
today Ioi Day1, Kong Hidu Teaching Success Ak,rank1, congratulations Chinateam score than Usateam High, 3au1ag, Wish day2:4ak! heard T1 check-in question T2 nausea problem T3 card time problemI heard the Nigerian team exploded 0 in order to elicit big news--back to business.the minimum cut model for this problem. Each experiment is like an S-side, and the cost is the cost, which accumulates into total. each instrument, like a T-edge, costs a fee to be spent. the instrument to be used in the experiment with the edge, the cost of the INF (indicating that can not be cut). just run the minimum cut.always thought Dinic wrote wrong originally was built map brain hole too big a place wrong tat
1#include <stdio.h>2#include <queue>3#include <string.h>4#include <iostream>5 using namespacestd;6 Const intv= About, e=100010;7 intHead[v],next[e],to[e],flow[e];8 intm,n,s,t,tot=1, total;9 BOOLVis[v];TenInlineintMinintAintb) { One returnA<b?a:b; A } -InlinevoidAddintUintVintFL) { -tot++; theto[tot]=v; -next[tot]=Head[u]; -head[u]=tot; -flow[tot]=FL; +tot++; -to[tot]=u; +next[tot]=Head[v]; Ahead[v]=tot; atflow[tot]=0; - } - - intC[v]; - -queue<int>Q; inInlinevoidClean () { - while(!q.empty ()) to Q.pop (); + } - theInlineBOOLBFs () { *Memset (c,0,sizeof(c)); $ Clean ();Panax Notoginseng Q.push (S); -c[s]=1; the while(!Q.empty ()) { + inttop=Q.front (); A Q.pop (); the for(intI=head[top];i;i=Next[i]) { + int_to=to[i],_flow=Flow[i]; - if(_flow==0|| C[_to]>0)Continue; $c[_to]=c[top]+1; $ Q.push (_to); - if(_to==t)return 1; - } the } - return 0;Wuyi } the - intDfsintNowintLow ) { Wu if(now==t)returnLow ; - intFlowx,r=Low ; About for(intI=head[now];i;i=Next[i]) { $ int_to=to[i],_flow=Flow[i]; - if(c[_to]!=c[now]+1|| _flow==0)Continue; -flowx=Dfs (_to,min (r,_flow)); -r-=flowx; AFLOW[I]-=FLOWX, flow[i^1]+=flowx; + if(!R)returnLow ; the } - if(R==low) c[now]=-1; $ returnlow-R; the } the theInlineintDinic () { the intansx=0; - while(BFS ())) Ansx+=dfs (S,210000000); in returnansx; the } the About intMain () { thescanf"%d%d",&m,&n); thes=0; thet=n+m+1; + for(intI=1, cost;i<=m;++i) { - Charstr; thescanf"%d%c",&cost,&str);Bayitotal+=Cost ; the Add (s,i,cost); the while(str!='\ n') { -scanf"%d%c",&cost,&str); -Add (I,cost+m,210000000); the } the } the for(intI=1, cost;i<=n;++i) { thescanf"%d",&Cost ); -Add (i+m,t,cost); the } the intanswer=total-dinic (); the for(intI=head[s];i;i=Next[i])94 if(Flow[i]) theprintf"%d", To[i]); theprintf"\ n"); the for(intI=head[t];i;i=Next[i]) {98 //cout<<i<< ' <<flow[i]<<endl; About if(Flow[i]) printf ("%d", to[i]-m); - }101printf"\n%d\n", answer);102 return 0;103}
View Code
Network flow Diagram has always been so pit tat
[Fzyzoj 1355] 8-2 space flight planning issues