POJ3686 The Windy's 【费用流】*
POJ3686 The Windy’s
Description
The Windy’s is a world famous toy factory that owns M top-class workshop to make toys. This year the manager receives N orders for toys. The manager knows that every order will take different amount of hours in different workshops. More precisely, the i-th order will take Zij hours if the toys are making in the j-th workshop. Moreover, each order’s work must be wholly completed in the same workshop. And a workshop can not switch to another order until it has finished the previous one. The switch does not cost any time.
The manager wants to minimize the average of the finishing time of the N orders. Can you help him?
Input
The first line of input is the number of test case. The first line of each test case contains two integers, N and M (1 ≤ N,M ≤ 50).
The next N lines each contain M integers, describing the matrix Zij (1 ≤ Zij ≤ 100,000) There is a blank line before each test case.
Output
For each test case output the answer on a single line. The result should be rounded to six decimal places.
Sample Input
3
3 4
100 100 100 1
99 99 99 1
98 98 98 1
3 4
1 100 100 100
99 1 99 99
98 98 1 98
3 4
1 100 100 100
1 99 99 99
98 1 98 98
Sample Output
2.000000
1.000000
1.333333
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cstdio>
#include<queue>
using namespace std;
#define INF 0x3f3f3f3f
#define N 10010
struct Edge{
int u,v,cap,flow,cost;
Edge(int xu,int xv,int xcap,int xflow,int xcost){
u=xu;v=xv;cap=xcap;flow=xflow;cost=xcost;
}
};
struct MCMF{
int s,t;
int d[N],f[N],p[N];
bool inq[N];
vector<Edge> E;
vector<int> G[N];
void clear(){
E.clear();
for(int i=0;i<N;i++)G[i].clear();
}
void add(int u,int v,int cap,int cost){
Edge w1(u,v,cap,0,cost);
Edge w2(v,u,0,0,-cost);
E.push_back(w1);
E.push_back(w2);
int m=E.size();
G[u].push_back(m-2);
G[v].push_back(m-1);
}
bool SPFA(int &flow,int &cost){
memset(inq,0,sizeof(inq));
memset(d,0x3f,sizeof(d));
queue<int> Q;
Q.push(s);
d[s]=0;f[s]=INF;
while(!Q.empty()){
int u=Q.front();Q.pop();inq[u]=0;
for(int i=0;i<G[u].size();i++){
Edge e=E[G[u][i]];
if(e.cap>e.flow&&d[e.v]>d[u]+e.cost){
d[e.v]=d[u]+e.cost;
p[e.v]=G[u][i];
f[e.v]=min(f[u],e.cap-e.flow);
if(!inq[e.v]){
Q.push(e.v);
inq[e.v]=1;
}
}
}
}
if(d[t]==INF)return false;
flow+=f[t];cost+=f[t]*d[t];
int u=t;
while(u!=s){
E[p[u]].flow+=f[t];
E[p[u]^1].flow-=f[t];
u=E[p[u]].u;
}
return true;
}
int Min_cost_Max_flow(){
int flow=0,cost=0;
while(SPFA(flow,cost));
return cost;
}
}mcmf;
int n,m,a[100];
int main(){
int T;scanf("%d",&T);
while(T--){
scanf("%d%d",&n,&m);
mcmf.clear();
mcmf.s=0;
mcmf.t=n+n*m+1;
for(int i=1;i<=n;i++){
mcmf.add(0,i,1,0);
for(int j=1;j<=m;j++){
int p;scanf("%d",&p);
for(int k=1;k<=n;k++)
mcmf.add(i,j*n+k,1,k*p);
}
}
for(int i=n+1;i<=n*m+n;i++)mcmf.add(i,n*m+n+1,1,0);
printf("%.6lf\n",mcmf.Min_cost_Max_flow()*1.0/n);
}
return 0;
}
POJ3686 The Windy's 【费用流】*的更多相关文章
- [poj3686]The Windy's(费用流)
题目大意: 解题关键:指派问题,待更. #include<cstdio> #include<cstring> #include<algorithm> #includ ...
- POJ 3686 The Windy's (费用流)
[题目链接] http://poj.org/problem?id=3686 [题目大意] 每个工厂对于每种玩具的加工时间都是不同的, 并且在加工完一种玩具之后才能加工另一种,现在求加工完每种玩具的平均 ...
- [bzoj1070][SCOI2007]修车——费用流
题目大意: 传送门 题解: 本题和(POJ3686)[http://poj.org/problem?id=3686]一题一模一样,而且还是数据缩小以后的弱化版QAQ,<挑战程序设计竞赛>一 ...
- POJ-3686 The Windy's KM算法 拆点题
参考:https://blog.csdn.net/sr_19930829/article/details/40680053 题意: 有n个订单,m个工厂,第i个订单在第j个工厂生产的时间为t[i][j ...
- hdu-5988 Coding Contest(费用流)
题目链接: Coding Contest Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Ot ...
- POJ2195 Going Home[费用流|二分图最大权匹配]
Going Home Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 22088 Accepted: 11155 Desc ...
- BZOJ3130: [Sdoi2013]费用流[最大流 实数二分]
3130: [Sdoi2013]费用流 Time Limit: 10 Sec Memory Limit: 128 MBSec Special JudgeSubmit: 960 Solved: 5 ...
- 洛谷 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 ...
- Codeforces 730I [费用流]
/* 不要低头,不要放弃,不要气馁,不要慌张 题意: 给两行n个数,要求从第一行选取a个数,第二行选取b个数使得这些数加起来和最大. 限制条件是第一行选取了某个数的条件下,第二行不能选取对应位置的数. ...
随机推荐
- Linux 下的jdk安装
Linux 下安装JDK1.8 https://www.cnblogs.com/xuliangxing/p/7066913.html http://www.oracle.com/technetwork ...
- codeforces781D Axel and Marston in Bitland
题目链接:codeforces781D 正解:$bitset$+状压$DP$ 解题报告: 考虑用$f[t][0.1][i][j]$表示从$i$出发走了$2^t$步之后走到了$j$,且第一步是走的$0$ ...
- ubuntu18.04里更新系统源和pip源
一.修改ubuntu系统源 我的ubuntu系统是在清华的开源网站上下的,所以我还以为他应该就帮我弄好源了,可是没想到下载的还是非常慢,看到下载的时候网址前还有个us,就知道不是国内源了.所以这里我们 ...
- javaScript tips —— 标签上的data属性
HTML5规定可以为元素添加非标准型的属性,只需添加前缀data-,这些属性可以随意添加,随意命名,目的是为元素提供与渲染无关的信息,或提供语义信息. 传统获取方式 'getAttribute' da ...
- PIL.Image与Base64 String的互相转换
https://www.jianshu.com/p/2ff8e6f98257 PIL.Image与Base64 String的互相转换 mona_alwyn 2018.01.18 19:02* 字数 ...
- JavaScript中Function Declaration与Function Expression 或者说 function fn(){}和var fn=function(){} 的区别
JavaScript是一种解释型语言,函数声明会在JavaScript代码加载后.执行前被解释,而函数表达式只有在执行到这一行代码时才会被解释. 在JS中有两种定义函数的方式, 1是:var aaa= ...
- 安装ectouch点击安装按钮无反应
首先按F12: 看看”控制台“或者”网络“是否说找不到页面404 如果出现404,则是/mobile/index.php?m=install&c=index&a=importing方法 ...
- 004——数组(四)array_search() array_change_key_case() array_chunk() array_combine() array_diff() array_diff_key() array_diff_assoc
<?php /** * in_array() 判断一个内容是否在数组中: */ /*$arr=array(1,2,3,4,5); if (in_array('1',$arr,TRUE)){ // ...
- 六.dbms_session(提供了使用PL/SQL实现ALTER SESSION命令)
1.概述 作用:提供了使用PL/SQL实现ALTER SESSION命令,SET ROLE命令和其他会话信息的方法 .2.包的组成 1).set_identifier说明:用于设置会话的客户ID号.语 ...
- jQuery实现点击式选项卡
参考:jQuery权威指南jQuery初步jQuery选择器jQuery操作domjQuery操作dom事件jQuery插件jQuery操作AjaxjQuery动画与特效jQuery实现导航栏jQue ...