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. continuous integration and continuous deployment in DW/BI

    deployment methodIn Redshift1, Deploy process: Drop and Refresh the view, Drop table, Create an empt ...

  2. 什么是mata标签

    <meta> 元素可提供有关页面的元信息(meta-information),比如针对搜索引擎和更新频度的描述和关键词. <meta> 标签位于文档的头部,不包含任何内容.&l ...

  3. mongoDB的基本使用----飞天博客

    Mongo的介绍:这个mongoDB官网说的好啊,MongoDB是一个开源的基于document的数据库,并且是优秀的NoSQL数据库,并且它是用C++写滴哈,非常有效率.一些什么特点呢? 全索引支持 ...

  4. 判断textview是否被截断

    Layout l = textview.getLayout(); if ( l != null){ int lines = l.getLineCount(); if ( lines > 0) i ...

  5. Http API设计

    Heroku团队根据heroku platform api和他们自己内部系统的实践经验总结了一些http api设计的准则,发布到了github上. 地址:https://github.com/int ...

  6. POJ 1039 Pipe 枚举线段相交

    Pipe Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 9493   Accepted: 2877 Description ...

  7. try{...} catch {...} finally{...} 各种情况代码的执行情况

    try { int i = Convert.ToInt32(Console.ReadLine()); Console.WriteLine("in the 'try'"); } ca ...

  8. visual studio 2015 删除空行 ,缩进css

    查找  ^(?([^\r\n])\s)*\r?$\r?\n

  9. css.day02.eg

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  10. LinqJoin方法

    Linq知识点总结: (一).构建两个List泛型集合 List<Person> list=new List<Person>()            {            ...