//可以网络流,但是要怎么分配每辆车让谁维修以及维修顺序呢。可以考虑每辆车维修时间对总结果的贡献,把每个修车人拆成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. html页面中完成查找功能

    最近在搞一个被很多人改了的框架,天天看代码看的头的晕了,不过感觉进步还挺大的,自己做了一个后台可配置前台查看两个库不同数据范围的东西,还挺满意,那天拿出来分享一下,今天先说一个这几天做的功能,就是ht ...

  2. NO.1:自学python之路------Hello world、判断、循环

    引言 人工智能如今越来越贴近生活,在这里将记录我自学python与tensorflow的过程.编程使用IDE:visual studio 2017,python版本3.6.4,tensorflow版本 ...

  3. Wampserver 修改根目录

    wampserver 默认根目录在 www 文件夹下 修改根目录方法如下: 1. 在打算存放项目或代码的位置新建文件夹(我建在了C:/MyProject) 2. 打开 httpd.conf 文件(该文 ...

  4. Amazon移除差评适用范围 - Amazon request for the feedback removal

    Greetings from Amazon Seller Support, Please accept my sincere apologies for the inconvenience cause ...

  5. Javascript中Generator(生成器)

    阅读目录 Generator的使用: yield yield* next()方法 next()方法的参数 throw方法() return()方法: Generator中的this和他的原型 实际使用 ...

  6. Wormholes POJ 3259(SPFA判负环)

    Description While exploring his many farms, Farmer John has discovered a number of amazing wormholes ...

  7. 软件工程课堂练习——找出1-n中1出现的个数

    题目:给定一个十进制的正整数,写下从1开始,到N的所有整数,然后数一下其中出现“1”的个数. 要求:写一个函数 f(N) ,返回1 到 N 之间出现的 “1”的个数.例如 f(12)  = 5. 在3 ...

  8. hdu1010--Tempter of the Bone(迷宫)

    题目链接http://acm.hdu.edu.cn/showproblem.php?pid=1010 Tempter of the Bone Time Limit: 2000/1000 MS (Jav ...

  9. udp 局域网群聊

    UDP: 无连接协议 udp协议发送数据,用的是数据报包的形式.(64KB以内)     发送端: 1.定义发送的datagramsocket对象,发送端可以不用定义端口 2.定义封装数据包datag ...

  10. 【Leetcode】322. Coin Change

    You are given coins of different denominations and a total amount of money amount. Write a function ...