把m个师傅拆成n个阶段,考虑每个人选上第某个阶段的某师傅对答案做出的贡献。

参见这里那里

#include <iostream>
#include <cstring>
#include <cstdio>
#include <queue>
using namespace std;
int m, n, uu, cnt, hea[605], ss, tt, minCost, dis[605], pre[605];
bool vis[605];
queue<int> d;
struct Edge{
int too, nxt, val, cst;
}edge[100005];
void add_edge(int fro, int too, int val, int cst){
edge[cnt].nxt = hea[fro];
edge[cnt].too = too;
edge[cnt].val = val;
edge[cnt].cst = cst;
hea[fro] = cnt++;
}
void addEdge(int fro, int too, int val, int cst){
add_edge(fro, too, val, cst);
add_edge(too, fro, 0, -cst);
}
bool bfs(){
memset(pre, -1, sizeof(pre));
memset(dis, 0x3f, sizeof(dis));
dis[ss] = 0;
d.push(ss);
vis[ss] = true;
while(!d.empty()){
int x=d.front();
d.pop();
vis[x] = false;
for(int i=hea[x]; i!=-1; i=edge[i].nxt){
int t=edge[i].too;
if(dis[t]>dis[x]+edge[i].cst && edge[i].val>0){
dis[t] = dis[x] + edge[i].cst;
pre[t] = i;
if(!vis[t]){
vis[t] = true;
d.push(t);
}
}
}
}
return dis[tt]!=0x3f3f3f3f;
}
void dinic(){
while(bfs()){
int tmp=0x3f3f3f3f;
for(int i=pre[tt]; i!=-1; i=pre[edge[i^1].too])
tmp = min(tmp, edge[i].val);
for(int i=pre[tt]; i!=-1; i=pre[edge[i^1].too]){
edge[i].val -= tmp;
edge[i^1].val += tmp;
minCost += tmp * edge[i].cst;
}
}
}
int main(){
memset(hea, -1, sizeof(hea));
cin>>m>>n;
ss = 0; tt = m * n + n + 1;
for(int i=1; i<=n; i++)
for(int j=1; j<=m; j++){
scanf("%d", &uu);
for(int k=1; k<=n; k++)
addEdge(i, j*n+k, 1, uu*k);
}
for(int i=1; i<=n; i++)
addEdge(ss, i, 1, 0);
for(int i=1; i<=m; i++)
for(int j=1; j<=n; j++)
addEdge(i*n+j, tt, 1, 0);
dinic();
printf("%.2lf\n", (double)minCost/n);
return 0;
}

最新文章

  1. kafka 搭建与使用
  2. Java利用POI导入导出Excel中的数据
  3. maven使用入门(pom)
  4. mp3 切割
  5. 如何给div加一个边框border样式
  6. Dynamicaly Typed(动态定型), Objective-C Runtime Programming
  7. php学习笔记——语言切换
  8. 转:Selenium Grid深入学习
  9. JavaScript 原型与继承机制详解
  10. Windows系统安装Azure CLI
  11. git笔记------自己学习git的心得
  12. metasploit下Windows下多种提权方式
  13. 利用隐藏 iframe 下载文件
  14. 前端 ----关于DOM的事件操作
  15. 前端 HTML body标签相关内容 常用标签 表单标签 form 表单控件分类
  16. topcoder srm 704 div1
  17. 记录常用的git命令
  18. google v8引擎常见问题
  19. iOS - 友盟集成QQ分享的AppID转换16进制的方法
  20. 测试用例和BUG描述规范

热门文章

  1. DetachedCriteria的简单使用
  2. markdown-Macdown
  3. Linux shell标准输入,标准输出,错误输出
  4. AutoIt上传非input控件方式的文件脚本
  5. OCX和DLL的区别
  6. HDU 2546 饭卡(带限制的01背包变形)
  7. (五)SpringMVC之使用Kaptcha实现验证码功能
  8. thinkphp 的事务回滚处理 和 原始PHP的事务回滚实例
  9. Codeforces Round #319 (Div. 2) B Modulo Sum (dp,鸽巢)
  10. hdu 5093 Battle ships (二分图)