http://poj.org/problem?id=3686

 #include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 30000
using namespace std; const int inf=<<;
int weight[][maxn],lx[maxn],ly[maxn],match[maxn],a[][];
bool sx[maxn],sy[maxn]; int n,m; bool path(int u)
{
sx[u]=true;
for(int v=; v<=n*m; v++)
{
if(!sy[v]&&lx[u]+ly[v]==weight[u][v])
{
sy[v]=true;
if(!match[v]||path(match[v]))
{
match[v]=u;
return true;
}
}
}
return false;
} int bestmatch()
{
memset(lx,-inf,sizeof(lx));
memset(ly,,sizeof(ly));
memset(match,,sizeof(match));
for(int i=; i<=n; i++)
{
for(int j=; j<=n*m; j++)
{
lx[i]=max(lx[i],weight[i][j]);
}
}
for(int u=; u<=n; u++)
{
while()
{
memset(sx,false,sizeof(sx));
memset(sy,false,sizeof(sy));
if(path(u)) break;
int dx=inf;
for(int i=; i<=n; i++)
{
if(sx[i])
{
for(int j=; j<=n*m; j++)
{
if(!sy[j]) dx=min(lx[i]+ly[j]-weight[i][j],dx);
}
}
}
for(int i=; i<=n; i++)
{
if(sx[i]) lx[i]-=dx;
}
for(int j=; j<=n*m; j++)
{
if(sy[j]) ly[j]+=dx;
}
} }
int sum=;
for(int i=; i<=n*m; i++)
sum+=weight[match[i]][i];
return -sum;
}
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
scanf("%d%d",&n,&m);
for(int i=; i<=n; i++)
{
for(int j=; j<=m; j++)
{
scanf("%d",&a[i][j]);
}
}
for(int i=; i<=n; i++)
{
for(int j=; j<=n; j++)
{
for(int k=; k<=m; k++)
{
weight[i][(k-)*n+j]=-a[i][k]*j;
}
}
}
printf("%.6f\n",1.0*bestmatch()/n);
}
return ;
}

poj 3686 The Windy's的更多相关文章

  1. POJ 3686 The Windy's(思维+费用流好题)

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 5362   Accepted: 2249 Descr ...

  2. [ACM] POJ 3686 The Windy&#39;s (二分图最小权匹配,KM算法,特殊建图)

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 4158   Accepted: 1777 Descr ...

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

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

  4. POJ 3686 The Windy's 最小费用最大流

    每个工厂拆成N个工厂,费用分别为1~N倍原费用. //#pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...

  5. POJ 3686 The Windy's (最小费用流或最佳完全匹配)

    题意:有n个订单m个车间,每个车间均可以单独完成任何一个订单.每个车间完成不同订单的时间是不同的.不会出现两个车间完成同一个订单的情况.给出每个订单在某个车间完成所用的时间.问订单完成的平均时间是多少 ...

  6. poj - 3686 The Windy's (KM算法)

    题意:n个订单和m个生产车间,每个订单在不同的车间生产所需要的时间不一样,并且每个订单只能在同一个车间中完成,直到这个车间完成这个订单就可以生产下一个订单.现在需要求完成n个订单的平均时间最少是多少. ...

  7. POJ 3686:The Windy's(最小费用最大流)***

    http://poj.org/problem?id=3686 题意:给出n个玩具和m个工厂,每个工厂加工每个玩具有一个时间,问要加工完这n个玩具最少需要等待的平均时间.例如加工1号玩具时间为t1,加工 ...

  8. Poj(3686),最小权匹配,多重匹配,KM

    题目链接 The Windy's | Time Limit: 5000MS | Memory Limit: 65536K | | Total Submissions: 4939 | Accepted: ...

  9. poj 3686

    The Windy's Time Limit: 5000MS   Memory Limit: 65536K Total Submissions: 3791   Accepted: 1631 Descr ...

随机推荐

  1. Python 列表排序方法reverse、sort、sorted详解

    python语言中的列表排序方法有三个:reverse反转/倒序排序.sort正序排序.sorted可以获取排序后的列表.在更高级列表排序中,后两中方法还可以加入条件参数进行排序. reverse() ...

  2. PHP学习之[第05讲]PHP5.4 循环结构、系统函数和自定义函数

    一.while/for/break/continue: while (expr){ statements } for (expr1:expr2:expr3){ statement } break n  ...

  3. [Firebase] Deploy you website to Firebase

    If you are looking for a host website, you can try Firebase, heroku or AWS... Today, I tried to depl ...

  4. Maven Build Life Cycle--reference

    What is Build Lifecycle? A Build Lifecycle is a well defined sequence of phases which define the ord ...

  5. KVM与VMware的性能比较

    结合网页http://www.linuxidc.com/Linux/2011-01/31755.htm等整理 物理环境内存4G ,CPU4个,动态硬盘120G KVM: 硬盘测试瞬间读取速度Timin ...

  6. iOS 启动连续闪退保护方案

    引言 “如果某个实体表现出以下任何一种特性,它就具备自主性:自我修复.自我保护.自我维护.对目标的自我控制.自我改进.” —— 凯文·凯利 iOS App 有时可能遇到启动必 crash 的绝境:每次 ...

  7. Python之路,Day16 - Django 进阶

    Python之路,Day16 - Django 进阶   本节内容 自定义template tags 中间件 CRSF 权限管理 分页 Django分页 https://docs.djangoproj ...

  8. visual studio中的一些实用的快捷键

    重置开发环境:使得开发工具恢复默认状态 方法:工具->导入和导出设置导向->重置所有设置->不保存 显示行号: 方法:工具->选项->所有语言->行号 在编程过程中 ...

  9. angular-ui-tree

    angular-ui-tree的github项目地址:https://github.com/angular-ui-tree/angular-ui-tree DEMO目录结构如下: bootstrap. ...

  10. HTML5 Canvas Text实例1

    1.简单实例1 <canvas width="300" height="300" id="canvasOne" class=" ...