There are n jobs, M machines, and you can rent or buy them for every kind of machine. Each work consists of several processes, each of which requires a machine to be completed, and you can do so by purchasing or renting a machine. Now give these parameters, for maximum profit input first row gives n,m (1<=n<=1200,1<=m<=1200) There will be N blocks of data, the first row of each piece of data gives the amount of money to accomplish this task (in [1,5000]) and how many processes The next few lines are two numbers per line, describing the machine number required to complete the operation and the cost of renting it (in [1,20000]) the last m line, each line gives the cost of the purchase of the machine (its [1,20000]) drunk ... and T and re and MLE ... People are too weak. Another naked question.
#include <bits/stdc++.h>using namespacestd;Const intINF =0x3f3f3f3f;#defineRep (I, J, K) for (int i = j; I <= K; ++i)Const intMAXN = -+ -;Const intMAXV =2400+ -, Maxe =3000000+Ten;structMaxflow {intEdge, HEAD[MAXV], To[maxe], next[maxe]; intCap[maxe]; Maxflow () {Edge=0; Memset (Head,-1,sizeofhead); } voidAddedge (intUintVintc) {To[edge]= V, Next[edge] =Head[u]; Cap[edge]=C; Head[u]= edge++; } voidAddedge (intUintVintc) {//printf ("%d%d%d\n", u, V, c);Addedge (U, V, c); Addedge (V, u,0); } ints, t; intCUR[MAXV], DIS[MAXV], que[maxv*maxv/Ten], front, back; BOOLBFs () {Que[front=back=0] =s; memset (Dis, INF,sizeof(int) * (t+Ten)); Dis[s]=0; while(Front <=Back ) { intU = que[front++]; for(intI=head[u]; i!=-1; I=Next[i]) { if(cap[i]>0&& dis[to[i]]>dis[u]+1) {Dis[to[i]]= dis[u]+1; que[++back] =To[i]; } } } returndis[t]!=INF; } intDfsintUinta) {if(U==t | | a==0) returnA; intflow=0, F; for(int&i=cur[u], V; i!=-1; I=Next[i])if(cap[i]>0&& dis[v=to[i]]==dis[u]+1&& (F=dfs (V, Min (A, cap[i])) >0) {Cap[i]-=f, cap[i^1]+=F; Flow+=f, a-=F; if(a==0) Break; } returnflow; } intMF () {intRET =0; while(BFS ()) {memcpy (cur, head,sizeof(int) * (t+Ten)); RET+=Dfs (S, INF); } returnret; }} MF;intN, M;intMain () {scanf ("%d%d", &n, &m); ints =0, t = n+m+1; intc, x, sum =0; intp, v; for(inti =1; I <= N; ++i) {scanf ("%d", &c); Sum+=C; Mf.addedge (S, I, c); scanf ("%d", &x); for(intj =1; J <= X; ++j) {scanf ("%d%d", &p, &v); Mf.addedge (i, N+p, v); }} rep (I,1, M) {scanf ("%d", &c); Mf.addedge (n+I, T, c); } Mf.s= S, mf.t =T; printf ("%d\n", sum-MF. MF ()); return 0;}
View Code
1391: [Ceoi2008]order