题解:
因为我们并不需要知道准确方案,而人数固定,要使得平均等待时间最小,也就是要使得总的等待时间最小。
因此我们将工人按每个时刻拆点,拆完之后向车子连边,流量为1,费用为k * 维修时间(倒数第k个修,所以对时间的贡献就是k * 维修时间,因为后面的k-1人要等它,自己也要等)
那这样会不会导致有人不需要等这个工人(因为他去找别人帮他修车了),但我们还是计入了他的等待时间呢?
这是不可能的,因为这样就说明那k-1个人中其实有些人是不存在的,既然这些人不存在,那就没必要倒数第k个修,直接往后推变成倒数k-1,k-2……修不就行了?
#include<bits/stdc++.h>
using namespace std;
#define R register int
#define INF 2139062143
#define AC 40000
#define ACway 400000
int n, m, s, t, tot = , ans, ansflow;
int dis[AC], Head[AC], last[AC], disflow[AC];
int date[ACway], Next[ACway], have[ACway], haveflow[ACway], cost[ACway];
bool z[AC];
deque <int> q; inline int read()
{
int x = ; char c = getchar();
while(c > '' || c < '') c = getchar();
while(c >= '' && c <= '') x = x * + c - '', c = getchar();
return x;
} inline int Min(int a, int b)
{
if(a < b) return a;
else return b;
} void add(int f, int w, int S, int c)
{
//printf("%d ---> %d flow is %d , cost %d\n",f,w,S,c);
date[++tot] = w , Next[tot] = Head[f] , haveflow[tot] = S , cost[tot] = c , Head[f] = tot;
date[++tot] = f , Next[tot] = Head[w] , cost[tot] = -c , Head[w] = tot;
} void cal()
{
int x = t;
if(dis[t] != INF)
{
while(x != s)
{
haveflow[last[x]] -= disflow[t];
haveflow[last[x] ^ ] += disflow[t];
x = date[last[x] ^ ];
}
ans += disflow[t] * dis[t];
}
} bool spfa()
{
int x, now;
z[s] = true, dis[s] = , disflow[s] = INT_MAX;
q.push_front(s);
while(!q.empty())
{
x = q.front();
q.pop_front();
z[x] = false;
for(R i = Head[x]; i ; i = Next[i])
{
now = date[i];
if(haveflow[i] && dis[now] > dis[x] + cost[i])
{
dis[now] = dis[x] + cost[i];
last[now] = i;
disflow[now] = Min(disflow[x], haveflow[i]);
if(!z[now] && now != t)//t就不要加进来的了
{
if(!q.empty() && dis[now] < dis[q.front()]) q.push_front(now);
else q.push_back(now);
z[now] = true;
}
}
}
}
cal();
return dis[t] != INF;
} void pre()
{
R a;
m = read(), n = read();
s = n + n * m + ;
t = s + ;
for(R i = ; i <= n; i++)
for(R j = ; j <= m; j++)
{
a = read();
for(R k = ; k <= n; k++)
add(i, n + (j - ) * n + k, , k * a);//将每个工人分成n个,分别代表n个时刻(以车记)
}
for(R i = ; i <= n; i++) add(s, i, , );
for(R i = n + ; i <= n + n * m; i++) add(i, t, , );
} void work()
{
memset(dis, 0x7f, sizeof(dis));
while(spfa())
memset(dis, 0x7f, sizeof(dis));
printf("%.2lf\n", (double)ans / (double)n);
} int main()
{
// freopen("in.in","r",stdin);
pre();
work();
// fclose(stdin);
return ;
}