POJ 3686 The Windy's 最小权值匹配
来源:互联网 发布:东北人假义气 知乎 编辑:程序博客网 时间:2024/09/21 06:33
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
33 4100 100 100 199 99 99 198 98 98 13 41 100 100 10099 1 99 9998 98 1 983 41 100 100 1001 99 99 9998 1 98 98
Sample Output
2.0000001.0000001.333333
//36044K579MS#include<stdio.h>#include<string.h>#include<algorithm>#define M 3007#define inf 0x3f3f3fusing namespace std;int g[M][M],map[M][M];int lx[M],ly[M];int slack[M],match[M];bool visx[M],visy[M];int n,m;void build(){ for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) for(int k=1; k<=n; k++) g[i][(j-1)*n+k]=-map[i][j]*k; m=n*m;}bool dfs(int cur){ visx[cur]=true; for(int y=1; y<=m; y++) { if(!visy[y]&&lx[cur]+ly[y]==g[cur][y]) { visy[y]=true; if(match[y]==-1||dfs(match[y])) { match[y]=cur; return true; } } } return false;}int KM(){ memset(match,-1,sizeof(match)); memset(ly,0,sizeof(ly)); for(int i=1; i<=n; i++) { lx[i]=-inf; for(int j=1; j<=m; j++) lx[i]=max(lx[i],g[i][j]); } for(int x=1; x<=n; x++) { while(true) { memset(visx,false,sizeof(visx)); memset(visy,false,sizeof(visy)); if(dfs(x))break; int d=inf; for(int j=1; j<=n; j++) if(visx[j]) { for(int k=1; k<=m; k++) { if(!visy[k]&&d>lx[j]+ly[k]-g[j][k]) { d=lx[j]+ly[k]-g[j][k]; } } } for(int i=1; i<=n; i++) if(visx[i]) lx[i]-=d; for(int i=1; i<=m; i++) if(visy[i]) ly[i]+=d; } } int result=0; for(int i=1; i<=m; i++) { if(match[i]!=-1&&g[match[i]][i]!=-inf) result+=g[match[i]][i]; } return result;}int main(){ int t; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); memset(g,0,sizeof(g)); for(int i=1; i<=n; i++) for(int j=1; j<=m; j++) scanf("%d",&map[i][j]); build(); int ans=KM(); printf("%.6f\n",-1.0*(double)ans/n); } return 0;}
- POJ 3686 The Windy's 最小权值匹配
- poj 3686 The Windy's(最小权值和)
- poj 3686 The Windy's 二分匹配 KM算法求最小权匹配
- poj 3686 The Windy's 二分图最小权和匹配KM
- POJ 3686 The Windy's(拆点、最小权匹配)
- POJ 3686 The Windy's (二分图最小权匹配 拆点 构图)
- Poj 3686 The Windy's【KM匹配】
- [ACM] POJ 3686 The Windy's (二分图最小权匹配,KM算法,特殊建图)
- POJ--3686[The Windy's] 最小费用流或KM
- poj 3686 The Windy's(最小费用最大流)
- 【POJ 3686 The Windy's】+ 最小费用流
- POJ 3686 The Windy's(最小费用最大流)
- poj 3686 The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's
- poj 3686 The Windy's
- POJ 3686 The Windy's
- POJ-3686-The Windy's
- 关于虚继承需要注意的几个问题
- Spring框架中的定时器 如何使用和配置
- c/c++ 下面学习的内容
- 未启用对服务器的远程访问
- 利用递归求n!
- POJ 3686 The Windy's 最小权值匹配
- Java内存管理——内存分配
- 【SkinUI实例】仿QQ界面设计第二十九课
- 虚拟机复制后访问网络问题
- WebWork配置文件详解
- JDBC调用Oracle存储过程
- Java写的抓取任意网页中email地址的小程序
- Android 安全机制
- UML类图