It's amazing to build a map. The graph is actually the bare cost stream.
--------------------------------------------------------------
#include <cstdio>#include <cstring>#include <algorithm>#include <iostream>#include <vector>#include <queue>#define REP (i,n) for (int i=0;i<n;++i)#define CLR (x,c) memset (x,c,sizeof (x) )#define REP (I,L,R) for (int i=l;i<=r;++i)using namespace std;const int inf=0x3f3f3f3f;const int maxn=602+5;struct Edge {int from,to,cap,flow,cost;Edge (int u,int v,int c,int f,int w):From (U), to (v), Cap (c), Flow (f), Cost (w) {}};struct MCMF {int D[MAXN];int P[MAXN];int A[MAXN];bool INQ[MAXN];int n,s,t;vector<int> G[MAXN];vector<edge> edges;void init (int n) {this->n=n;Rep (I,n) g[i].clear ();edges.clear ();}void Addedge (int u,int v,int c,int w) {Edges.push_back (Edge (u,v,c,0,w));Edges.push_back (Edge (v,u,0,0,-w));G[u].push_back (Edges.size ()-2);G[v].push_back (Edges.size ()-1);}bool SPFA (int &flow,int &cost) {CLR (d,inf); CLR (inq,0) ;queue<int> Q; q.push (s);a[s]=inf; d[s]=0; inq[s]=1; p[s]=0 ;While (!q.empty ()) {int X=q.front (); Q.pop ();inq[x]=0;Rep (I,g[x].size ()) {Edge &e=edges[g[x][i]];if (e.cap>e.flow && d[e.to]>d[x]+e.cost) {D[e.to]=d[x]+e.cost;P[e.to]=g[x][i];a[e.to]=min (a[x],e.cap-e.flow);if (!inq[e.to]) {Q.push (e.to); inq[e.to]=1;}}}}if (D[t]==inf) return false;Flow+=a[t];Cost+=a[t]*d[t];int x=t;While (x!=s) {Edges[p[x]].flow+=a[t];Edges[p[x]^1].flow-=a[t];X=edges[p[x]].from;}return true;}int mincost (int s,int t) {this->s=s; this->t=t;int flow=0,cost=0;while (SPFA (Flow,cost));return cost;}} g; int main (){//freopen ("test.in", "R", stdin);//freopen ("Test.out", "w", stdout); int m,n;scanf ("%d%d", &m,&n);int t=n*m;int s=0,t=t+n+1;G.init (t+1);Rep (i,1,n)Rep (j,m) {int W; scanf ("%d", &w);Rep (k,1,n) G.addedge (j*n+k,t+i,1,w*k); }Rep (i,1,n) G.addedge (i+t,t,1,0);Rep (i,1,t) G.addedge (0,i,1,0);printf ("%.2lf\n", (double) g.mincost (s,t)/n); return 0;}
--------------------------------------------------------------
1070: [SCOI2007] Car repair time limit: 1 Sec Memory Limit: 162 MB
Submit: 2762 Solved: 1099
[Submit] [Status] [Discuss] Description
At the same time, N-owners took their car to the car repair center. The repair center has a total of M technical staff, different technical staff for different vehicles to repair the time is different. It is now necessary to arrange the cars and sequences repaired by the M technician, which will allow the average customer to wait for the least amount of time. Note: The customer's waiting time refers to the time taken from his car to the repair center to the completion of the repair.
Input
The first line has two m,n, which indicates the number of technicians and customers. Next n rows, m integers per line. The number of i+1 in section J indicates the time t required for the maintenance of the first I vehicle by the J-Technician.
Output
The minimum average wait time, the answer is exactly 2 digits after the decimal point.
Sample Input2 2
3 2
1 4Sample Output1.50HINT
Data range: (2<=m<=9,1<=n<=60), (1<=t<=1000)
Bzoj 1070: [SCOI2007] repair vehicle (minimum cost maximum flow)