#include <bits/stdc++.h>
using namespace std;
#define inf 1000000000000000
#define V 100100
#define E 500100
typedef long long int ll;
struct edge {
int to, next;
ll capa, cost;
};
int cnt = 0, head[V], n, m; edge node[E];
inline void add(int fir, int nxt, ll w, ll c) {
node[cnt].to = nxt,
node[cnt].capa = w,
node[cnt].cost = c,
node[cnt].next = head[fir],
head[fir] = cnt++;
}
int s, t, cur[V]; deque<int>que; ll dep[V], sum = 0, cost = 0;
bool vis[V];
inline bool spfa(){
for(register int i = 1; i <= t; ++i)dep[i] = inf;
dep[s] = 0; que.push_back(s); int u, v;
while(!que.empty()){
v = que.front(); que.pop_front();
for(register int i = head[v]; i != -1; i = node[i].next){
u = node[i].to;
if(dep[v] + node[i].cost < dep[u] && node[i].capa){
dep[u] = dep[v] + node[i].cost;
if(!que.empty() && dep[u]<dep[que.front()])que.push_front(u);
else que.push_back(u);
}
}
}
return (dep[t] != inf);
}
ll dfs(register int v,register ll flow){
if(flow == 0 || v == t)return flow; ll used = 0, wei = 0;
vis[v] = true;
for(register int i = cur[v]; i != -1; i = node[i].next){
cur[v] = i;
if(!vis[node[i].to] && dep[node[i].to] == dep[v] + node[i].cost && node[i].capa){
wei = dfs(node[i].to, min(flow - used, node[i].capa));
if(wei){
node[i].capa -= wei,
node[i ^ 1].capa += wei,
used += wei,
cost += node[i].cost * wei;
}
}
if(used == flow)break;
}
vis[v] = false;
return used;
}
inline void Dinic(){
while(spfa()){
memcpy(cur, head, (t + 1) * sizeof(int));
sum += dfs(s, inf);
}
}
inline void addE(int u, int v, ll w, ll c){
add(u, v, w, c);
add(v, u, 0, -c);
}
ll Time[205][205];
int main() {
ios::sync_with_stdio(0);
cin.tie(); cout.tie();
memset(head, -1, V * sizeof(int));
cin >> m >> n; s = n * m + n + 1, t = s + 1;
for(int i = 1; i <= n; i++)addE(s, i, 1, 0);
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
cin >> Time[i][j];
}
}
for(int i = 1; i <= m; i++){
for(int j = 1; j <= n; j++){
addE(i * n + j, t, 1, 0);
}
}
for(int i = 1; i <= n; i++){
for(int j = 1; j <= m; j++){
for(int k = 1; k <= n; k++){
addE(i, j * n + k, 1, k * Time[i][j]);
}
}
}
Dinic();
cout << fixed << setprecision(2) << (double)cost / (double)n;
return 0;
}剪贴板
剪贴板 5ezqrrhh
剪贴板信息
剪贴板信息
- 收录
- 更新