POJ 3686 The windy ' s minimum weight matching

Source: Internet
Author: User

Click on the link to open the windy ' s
Time Limit: 5000MS Memory Limit: 65536K
Total Submissions: 3788 Accepted: 1630

Description

The windy's is a world famous toy factory, owns M Top-class workshop to make toys. This year, the manager receives N orders for toys. The manager knows that every order would take different amount of hours in different workshops. More precisely, the I-th order would take zij hours if the toys is making in the J-th Workshop. Moreover, each order's work must is 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 was the number of the test case. The first line of each test case contains the 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

The For each test case output the answer to a single line. The result should is 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

there are n tasks need m machine to do, each machine can only do one task at a time, and each task must go through the M machine to complete, first give you each task at the time of each machine, ask the minimum average time is how much. complete the total task time is the actual time + wait time, set to complete 1,2,3....N time is t1,t2,t3...tn, then the total time is t=t1+ (T1+T2) + (T1+T2+T3) +......+ (T1+T2+...+TN) =t1*n+t2* (n-1) +t3* (n-2) +tn the K-task processes the Tk*j on the countdown J machine. each machine can handle n tasks, splitting each machine into n points, 1~n represents a task on this machine, each of the countdown is processed, for each task I, Machine J split each point K, connected to a-map[i][j]*k weight of the edge.
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;}


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.