//可以网络流,但是要怎么分配每辆车让谁维修以及维修顺序呢。可以考虑每辆车维修时间对总结果的贡献,把每个修车人拆成n个点共n*m个点,
//n辆车连向这n*m个点,流量1,费用k*修车时间,其中k(1=<k<=n)表示这辆车是这个技术人员修的倒数第k俩车,他后面k-1辆被同一个人维修的车
//都要等待他修好,因此他的贡献值就是k*维修时间。然后源点连向n辆车,n*m个点连向汇点。
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
using namespace std;
const int INF=0x7fffffff;
const int MAXN=;
const int MAXM=;
int N,a[][],tot,head[MAXN+],pre[MAXN],dis[MAXN];
bool vis[MAXN+];
struct Edge
{
int to,next,cap,flow,cost;
}edge[MAXM+];
void init(int x)
{
N=x;
tot=;
memset(head,-,sizeof(head));
}
void add(int x,int y,int w,int c)
{
edge[tot].to=y;
edge[tot].cap=w;
edge[tot].cost=c;
edge[tot].flow=;
edge[tot].next=head[x];
head[x]=tot++;
edge[tot].to=x;
edge[tot].cap=;
edge[tot].cost=-c;
edge[tot].flow=;
edge[tot].next=head[y];
head[y]=tot++;
}
bool Spfa(int s,int t)
{
queue<int>q;
for(int i=;i<=N;i++){
vis[i]=;
dis[i]=INF;
pre[i]=-;
}
vis[s]=;
dis[s]=;
q.push(s);
while(!q.empty()){
int u=q.front();q.pop();
vis[u]=;
for(int i=head[u];i!=-;i=edge[i].next){
int v=edge[i].to;
if(edge[i].cap>edge[i].flow&&dis[v]>dis[u]+edge[i].cost){
dis[v]=dis[u]+edge[i].cost;
pre[v]=i;
if(!vis[v]){
vis[v]=;
q.push(v);
}
}
}
}
if(pre[t]==-) return ;
return ;
}
int MaxCostFlow(int s,int t)
{
int Flow=,Cost=;
while(Spfa(s,t)){
int Min=INF;
for(int i=pre[t];i!=-;i=pre[edge[i^].to])
Min=min(Min,edge[i].cap-edge[i].flow);
for(int i=pre[t];i!=-;i=pre[edge[i^].to]){
edge[i].flow+=Min;
edge[i^].flow-=Min;
Cost+=edge[i].cost*Min;
}
Flow+=Min;
}
return Cost;
}
int main()
{
int n,m;
while(scanf("%d%d",&m,&n)==){
init(n+n*m+);
for(int i=;i<=n;i++){
add(,i,,);
for(int j=;j<=m;j++)
scanf("%d",&a[i][j]);
}
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
for(int k=;k<=n;k++){
add(i,j*n+k,,k*a[i][j]);
}
}
}
for(int i=n+;i<=n+n*m;i++)
add(i,n+n*m+,,);
printf("%.2lf\n",1.0*MaxCostFlow(,n+n*m+)/(1.0*n));
}
return ;
}

bzoj 1070 费用流的更多相关文章

  1. bzoj 3171 费用流

    每个格拆成两个点,出点连能到的点的入点,如果是箭头指向 方向费用就是0,要不就是1,源点连所有出点,所有入点连 汇点,然后费用流 /********************************** ...

  2. bzoj 1449 费用流

    思路:先把没有进行的场次规定双方都为负,对于x胜y负 变为x + 1胜 y - 1 负所需要的代价为 2 * C[ i ] * x  - 2 * D[ i ] * y + C[ i ] + D[ i ...

  3. BZOJ 1061费用流

    思路: 我们可以列出几个不等式 用y0带进去变成等式 下-上 可以消好多东西 我们发现 等式左边的加起来=0 可以把每个方程看成一个点 正->负 连边 跑费用流即可 //By SiriusRen ...

  4. BZOJ 1283 费用流

    思路: 最大费用最大流 i->i+1 连边k 费用0 i->i+m (大于n的时候就连到汇) 连边1 费用a[i] //By SiriusRen #include <queue> ...

  5. bzoj 2668 费用流

    我们可以把初始状态转化为目标状态这一约束转化为将黑子移动到目标状态所需要的最少步数. 除了初始点和目标点之外,剩下的点如果被经过那么就会被交换两次,所以我们将一个点拆成3个点,a,b,c,新建附加源点 ...

  6. bzoj 2245 费用流

    比较裸 源点连人,每个人连自己的工作,工作连汇,然后因为人的费用是 分度的,且是随工作数非降的,所以我们拆边,源点连到每个人s+1条边 容量是每段的件数,费用是愤怒 /**************** ...

  7. BZOJ 3280 费用流

    思路: 同BZOJ 1221 //By SiriusRen #include <queue> #include <cstdio> #include <cstring> ...

  8. BZOJ 4514 费用流

    思路: 懒得写了 http://blog.csdn.net/werkeytom_ftd/article/details/51277482 //By SiriusRen #include <que ...

  9. [BZOJ 1070] [SCOI2007] 修车 【费用流】

    题目链接:BZOJ - 1070 题目分析 首先想到拆点,把每个技术人员拆成 n 个点,从某个技术人员拆出的第 i 个点,向某辆车连边,表示这是这个技术人员修的倒数第 i 辆车.那么这一次修车对整个答 ...

随机推荐

  1. 228. [LeetCode] Summary Ranges

    Given a sorted integer array without duplicates, return the summary of its ranges. Example 1: Input: ...

  2. PReLU——Delving Deep into Rectifiers: Surpassing Human-Level Performance on ImageNet Classification

    1. 摘要 在 \(ReLU\) 的基础上作者提出了 \(PReLU\),在几乎没有增加额外参数的前提下既可以提升模型的拟合能力,又能减小过拟合风险. 针对 \(ReLU/PReLU\) 的矫正非线性 ...

  3. Python模块random使用详情

    python常用模块目录 1.random.random()#用于生成一个0到1的随机浮点数:0<= n < 1.0 import random mcw = random.random() ...

  4. Python20-Day02

    1.数据 数据为什么要分不同的类型 数据是用来表示状态的,不同的状态就应该用不同类型的数据表示: 数据类型 数字(整形,长整形,浮点型,复数),字符串,列表,元组,字典,集合 2.字符串 1.按索引取 ...

  5. Coloring a Tree(耐心翻译+思维)

    Description You are given a rooted tree with n vertices. The vertices are numbered from 1 to n, the ...

  6. ACM ICPC 2016–2017, NEERC, Northern Subregional Contest Problem J. Java2016

    题目来源:http://codeforces.com/group/aUVPeyEnI2/contest/229510 时间限制:2s 空间限制:256MB 题目大意: 给定一个数字c 用 " ...

  7. HDU 5195 DZY Loves Topological Sorting 拓扑排序

    题目链接: hdu:http://acm.hdu.edu.cn/showproblem.php?pid=5195 bc(中文):http://bestcoder.hdu.edu.cn/contests ...

  8. SQL Server数据库复制

    事务复制 事务复制是一种复制类型,对订阅服务器上应用的初始数据快照,然后当发布服务器上发生数据修改时,将捕获到个别的事务并传播到订阅服务. 事务复制的原理是先将发布服务器数据库中的初始快照发送到各订阅 ...

  9. rsyslog配置文件详解(rsyslog.conf)

    # rsyslog configuration file # For more information see /usr/share/doc/rsyslog-*/rsyslog_conf.html # ...

  10. 0429团队项目-Scrum团队成立

    Scrum团队成立 团队名称:开拓者 团队目标:努力让每一个小伙伴在学会走路的基础上学会跑. 团队口号:我们要的只是这片天而已. 团队照:正面照+背影照(那就是为什么组名叫开拓者) 5.2 角色分配 ...