题目大意:

解题关键:指派问题,待更。

#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cmath>
#include<vector>
#include<queue>
#define inf 0x3f3f3f3f
#define MAX_V 10010
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
struct edge{int to,cap,cost,rev;};
int V;
vector<edge>G[MAX_V];
int h[MAX_V],dist[MAX_V],prevv[MAX_V],preve[MAX_V];
void add_edge(int from,int to,int cap,int cost){
G[from].push_back((edge){to,cap,cost,G[to].size()});
G[to].push_back((edge){from,,-cost,G[from].size()-});
} int min_cost_flow(int s,int t,int f){
int res=;
fill(h,h+V,);
while(f>){
priority_queue<P,vector<P>,greater<P> >que;
fill(dist,dist+V+,inf);
dist[s]=;
que.push(P(,s));
while(!que.empty()){
P p=que.top();que.pop();
int v=p.second;
if(dist[v]<p.first) continue;
for(int i=;i<G[v].size();i++){
edge &e=G[v][i];
if(e.cap>&&dist[e.to]>dist[v]+e.cost+h[v]-h[e.to]){
dist[e.to]=dist[v]+e.cost+h[v]-h[e.to];
prevv[e.to]=v;
preve[e.to]=i;
que.push(P(dist[e.to],e.to));
}
}
}
if(dist[t]==inf) return -;
for(int v=;v<V;v++) h[v]+=dist[v]; //增广
int d=f;
for(int v=t;v!=s;v=prevv[v]) d=min(d,G[prevv[v]][preve[v]].cap);
f-=d;
res+=d*h[t];
for(int v=t;v!=s;v=prevv[v]){
edge &e=G[prevv[v]][preve[v]];
e.cap-=d;
G[v][e.rev].cap+=d;
}
}
return res;
}
int n,m,t1,t2,t3,t4;
int z[][];
int main(){
int _;
scanf("%d",&_);
while(_--){
memset(G,,sizeof G);
scanf("%d%d",&n,&m);
for(int i=;i<n;i++){
for(int j=;j<m;j++){
scanf("%d",&z[i][j]);
}
}
int s=n+n*m,t=s+;
V=t+;
for(int i=;i<n;i++) add_edge(s,i,,);
for(int j=;j<m;j++){
for(int k=;k<n;k++){
add_edge(n+j*n+k,t,,);
for(int i=;i<n;i++){
add_edge(i,n+j*n+k,,(k+)*z[i][j]);
}
}
}
printf("%.6f\n",(double)min_cost_flow(s,t,n)/n);
}
return ;
}

[poj3686]The Windy's(费用流)的更多相关文章

  1. POJ3686 The Windy's 【费用流】*

    POJ3686 The Windy’s Description The Windy’s is a world famous toy factory that owns M top-class work ...

  2. POJ 3686 The Windy's (费用流)

    [题目链接] http://poj.org/problem?id=3686 [题目大意] 每个工厂对于每种玩具的加工时间都是不同的, 并且在加工完一种玩具之后才能加工另一种,现在求加工完每种玩具的平均 ...

  3. [bzoj1070][SCOI2007]修车——费用流

    题目大意: 传送门 题解: 本题和(POJ3686)[http://poj.org/problem?id=3686]一题一模一样,而且还是数据缩小以后的弱化版QAQ,<挑战程序设计竞赛>一 ...

  4. POJ-3686 The Windy's KM算法 拆点题

    参考:https://blog.csdn.net/sr_19930829/article/details/40680053 题意: 有n个订单,m个工厂,第i个订单在第j个工厂生产的时间为t[i][j ...

  5. hdu-5988 Coding Contest(费用流)

    题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Ot ...

  6. POJ2195 Going Home[费用流|二分图最大权匹配]

    Going Home Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 22088   Accepted: 11155 Desc ...

  7. BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]

    3130: [Sdoi2013]费用流 Time Limit: 10 Sec  Memory Limit: 128 MBSec  Special JudgeSubmit: 960  Solved: 5 ...

  8. 洛谷 1004 dp或最大费用流

    思路: dp方法: 设dp[i][j][k][l]为两条没有交叉的路径分别走到(i,j)和(k,l)处最大价值. 则转移方程为 dp[i][j][k][l]=max(dp[i-1][j][k-1][l ...

  9. Codeforces 730I [费用流]

    /* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给两行n个数,要求从第一行选取a个数,第二行选取b个数使得这些数加起来和最大. 限制条件是第一行选取了某个数的条件下,第二行不能选取对应位置的数. ...

随机推荐

  1. iTerm2 + Oh My Zsh

    iTerm2 http://iterm2.com/downloads.html https://iterm2.com/downloads/stable/iTerm2-2_1_4.zip Oh My Z ...

  2. 项目管理理论与实践(5)——UML应用(下)

    本篇文章介绍UML的相关知识.参考<UML从入门到精通> 六.状态机视图 1. 概述 状态机视图通过对类对象的生存周期建立模型来描述对象随时间变化的动态行为.状态是给定类的对象的一组属性值 ...

  3. 22 Python 模块与包

    一 模块 1 什么是模块? 常见的场景:一个模块就是一个包含了python定义和声明的文件,文件名就是模块名字加上.py的后缀. 但其实import加载的模块分为四个通用类别: 1 使用python编 ...

  4. 20 Python 常用模块

    collections模块 在内置数据类型(dict.list.set.tuple)的基础上,collections模块还提供了几个额外的数据类型:Counter.deque.defaultdict. ...

  5. SpringMVC_总结_03_SpringMVC相关注解

    一.前言 在前面的小节中,我们配置了注解驱动和自动扫描包,然后就可以使用SpringMVC相关注解了. 二.@Controller @Controller用来修饰类,源码如下: package org ...

  6. java学习笔记 --- 网络编程(网络的基础知识)

    1.网络模型: |--OSI(open stystem Interconnection开放式系统互连) |--特点: 是一种异构系统互连的分层结构:提供了控制互连系统交互规则的标准骨架:定义一种抽象结 ...

  7. 【pandas】pandas.DataFrame.rename()---重置索引名称

    官方文档 github地址 例子: 创建DataFrame ### 导入模块 import numpy as np import pandas as pd import matplotlib.pypl ...

  8. centos 下配置oracle11gR2开机自启

    这里使用的环境是 CentOS 6.6 ,并且已经装好了oracle11gR2 oracle启动分为两个步骤: 1.启动监听 2.启动服务 1.root 用户下修改ORATAB(将N该为Y): [ro ...

  9. Unity Shader 创建程序纹理贴图

    创建一个脚本 附加到一个游戏体上 using UnityEngine;using System.Collections; public class ProceduralTexture : MonoBe ...

  10. 【转】JVM虚拟性能分析

    JDK自带的JAVA性能分析工具.它已经在你的JDK bin目录里了,只要你使用的是JDK1.6 Update7之后的版本.点击一下jvisualvm.exe图标它就可以运行了. 这里是VisualV ...