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. 关于openoffice英文乱码的问题

    首先选中乱码的部分,然后在右边的侧栏中看到其字体,尝试改变它的字体,看会不会显示正常,如果可以,先记住这两种字体.然后:    工具->选项->字体        然后在使用替换表打上勾, ...

  2. [PWA] 18. Clean the photo cache

    We cannot let photo always keep caching new data without clean the old data. If message is not displ ...

  3. 关于Build Active Architecture Only属性

    关于Build Active Architecture Only属性 Architecture 属性在BuildSetting里. 这个属性设置为yes,是为了debug的时候编译速度更快,它只编译当 ...

  4. HTML中常见的各种位置距离以及dom中的坐标讨论

    最近在学习JavaScript,特意买了一本犀牛角书来看看,尼玛一千多页,看的我头昏脑涨,翻到DOM这章节,突然记起平常在使用DOM时,碰到了好多的这个dom里面的各种宽度,高度,特意在此写一写,写的 ...

  5. (转)Android中使用ormlite实现持久化(一)--HelloOrmLite

    Android中内置了sqlite,但是常用的开发语言java是面向对象的,而数据库是关系型的,二者之间的转化每次都很麻烦(主 要是我对sql语言不熟悉).而Java Web开发中有很多orm框架,但 ...

  6. Java基础知识强化之IO流笔记08:异常的注意事项

    1. 异常注意事项: (1)子类重写父类方法时候,子类的方法必须抛出相同的异常或者父类异常的子类.(父亲坏了,儿子不能比父亲更坏) (2)如果父类抛出多个异常,子类重写父类时候,只能抛出相同的异常或者 ...

  7. SpringMVC10数据验证

    /** * @NotBlank 作用在String * @NotEmpty 作用在集合上 * @NotNull 作用在基本数据类型上 * */ public class User { @NotNull ...

  8. Java编程思想-泛型-简单泛型例子

    基本类型无法做为类型参数 代码如下: /** * */ package test.thinkinjava.Generics; import java.util.ArrayList; import ja ...

  9. 静态html传参数

    记下来备忘 a.html <html> <head> <body> <a href="c.html?test=大师大师" target=& ...

  10. linux术语解析(持续更新)

    1.linux内核有个版本,分别是 longterm: 提供长期支持的内核版本 stable: 稳定版本 Beta 测试版