Ref: 40680053
Test instructions
There are n orders, m factories, the first order in the J Factory production time is t[i][j], the same factory can produce multiple orders, but only one order at a time, that is, if the first production of a order, then B orders to wait until a production after the production, Ask n orders the minimum amount of time required to complete the production of this M factory.
Ideas:
This problem seems to use the cost flow can also, the idea of building a map seems to be the same. The time spent on each order is related to the order of waiting in the factory. Obviously, if a factory has a K order, then the first commodity T1 time, the Second product is (T1 + T2) time, the third product is (T1+T2+T3) ... Because we are considering the total time, add up = T1 + (t1 + t2) + (t1 + t2 + T3) ... (T1 + t2 ... tk). Go to parentheses to find K*t1 + (K-1) * t2 + ... tk. But here you may be as overwhelmed as I am. T1 contributed K times, T2 contributed (K-1) times, TK contributed one times. To make it clearer, a factory's Countdown I order contributes to the time of I * t. So we're going to open n points for each factory, and this point represents the contribution of an item on the left at the time of paragraph (1~n). Is the idea of splitting, and each factory splits n cases.
Picture may be better understood (copied from reference)
#include <algorithm>#include<iterator>#include<iostream>#include<cstring>#include<iomanip>#include<cstdlib>#include<cstdio>#include<string>#include<vector>#include<bitset>#include<cctype>#include<queue>#include<cmath>#include<list>#include<map>#include<Set>//#include <unordered_map>//#include <unordered_set>//#include <ext/pb_ds/assoc_container.hpp>//#include <ext/pb_ds/hash_policy.hpp>using namespacestd;//#pragma GCC optimize (3)//#pragma COMMENT (linker, "/stack:102400000,102400000")//C + +#defineLson (L, Mid, RT << 1)#defineRson (mid + 1, R, RT << 1 | 1)#defineDebug (x) cerr << #x << "=" << x << "\ n";#definePB Push_back#definePQ Priority_queuetypedefLong Longll;typedef unsignedLong LongUll;typedef pair<ll, LL >Pll;typedef pair<int,int>Pii;typedef pair<int,pii>P3;//priority_queue<int> Q;//This is a big root heap Q//priority_queue<int,vector<int>,greater<int> >q;//This is a little Gan q//__gnu_pbds::cc_hash_table<int,int>ret[11]; //It's a quick hash_map.#defineFi first#defineSe Second//#define Endl ' \ n '#defineOKC Ios::sync_with_stdio (false); Cin.tie (0)#defineFT (A,B,C) for (int a=b; A <= C;++a)//used to press the line#defineREP (I, J, K) for (int i = j; i < K; ++i)//Priority_queue<int, Vector<int>, greater<int> >que;Constll mos = 0X7FFFFFFFLL;//2147483647Constll nmos = 0X80000000LL;//-2147483648Const intINF =0x3f3f3f3f;Constll inff = 0X3F3F3F3F3F3F3F3FLL;// -Const DoublePi=acos (-1.0); template<typename t>inline T read (t&x) {x=0;intf=0;CharCh=GetChar (); while(ch<'0'|| Ch>'9') f|= (ch=='-'), ch=GetChar (); while(ch>='0'&&ch<='9') x=x*Ten+ch-'0', ch=GetChar (); returnx=f?-x:x;}/*-----------------------Showtime----------------------*/ Const intMAXN = -; intT[MAXN][MAXN]; intmp[maxn][maxn*MAXN]; intvisx[maxn],visy[maxn*MAXN]; intXn,xm,minz; intlinkx[maxn],linky[maxn*MAXN]; intWX[MAXN],WY[MAXN *MAXN]; BOOLDfsintx) {Visx[x]=true; for(intI=1; i<=xm; i++){ if(!Visy[i]) { intt = wx[x] + wy[i]-Mp[x][i]; if(t==0) {Visy[i]=true; if(!linky[i] | |DFS (Linky[i])) {Linky[i]=x; LINKX[X]=i; return true; } } Else if(t>0) Minz =min (Minz, t); } } return false; } intkm () { for(intI=1; I<=max (XN,XM); i++) Linkx[i]= Linky[i] =0; for(intI=1; i<=xm; i++) Wy[i] =0; for(intI=1; i<=xn; i++) {Wx[i]= -inf; for(intj=1; j<=xm; J + +) {Wx[i]=Max (Wx[i], mp[i][j]); } } for(intI=1; i<=xn; i++){ while(true) {memset (VISX,0,sizeof(VISX)); memset (Visy,0,sizeof(Visy)); Minz=inf; if(Dfs (i)) Break; for(intj=1; j<=xn; J + +)if(Visx[j]) wx[j]-=Minz; for(intj=1; j<=xm; J + +)if(Visy[j]) wy[j] + =Minz; } } intAns =0; for(intI=1; i<=xn; i++){ if(linkx[i]>0) {ans-=Mp[i][linkx[i]]; } } returnans; }intMain () {intT Cin>>T; while(t--){ intn,m; scanf ("%d%d", &n, &m); for(intI=1; i<=n; i++){ for(intj=1; j<=m; J + +) {scanf ("%d", &T[i][j]); } } for(intI=1; i<=n; i++){ for(intj=1; j<=m; J + +){ for(intk=1; k<=n; k++) {mp[i][(J-1) *n + K] =-K *T[i][j]; } }} xn= N,XM = m*N; intAns =km (); printf ("%.6f\n", ans *1.0/N); } return 0;}
POJ3686
POJ-3686 The windy ' s km algorithm disassembly humorous