poj 3686 The Windy's
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的更多相关文章
- POJ 3686 The Windy's(思维+费用流好题)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 5362 Accepted: 2249 Descr ...
- [ACM] POJ 3686 The Windy's (二分图最小权匹配,KM算法,特殊建图)
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 4158 Accepted: 1777 Descr ...
- POJ 3686 The Windy's (费用流)
[题目链接] http://poj.org/problem?id=3686 [题目大意] 每个工厂对于每种玩具的加工时间都是不同的, 并且在加工完一种玩具之后才能加工另一种,现在求加工完每种玩具的平均 ...
- POJ 3686 The Windy's 最小费用最大流
每个工厂拆成N个工厂,费用分别为1~N倍原费用. //#pragma comment(linker, "/STACK:1024000000,1024000000") #includ ...
- POJ 3686 The Windy's (最小费用流或最佳完全匹配)
题意:有n个订单m个车间,每个车间均可以单独完成任何一个订单.每个车间完成不同订单的时间是不同的.不会出现两个车间完成同一个订单的情况.给出每个订单在某个车间完成所用的时间.问订单完成的平均时间是多少 ...
- poj - 3686 The Windy's (KM算法)
题意:n个订单和m个生产车间,每个订单在不同的车间生产所需要的时间不一样,并且每个订单只能在同一个车间中完成,直到这个车间完成这个订单就可以生产下一个订单.现在需要求完成n个订单的平均时间最少是多少. ...
- POJ 3686:The Windy's(最小费用最大流)***
http://poj.org/problem?id=3686 题意:给出n个玩具和m个工厂,每个工厂加工每个玩具有一个时间,问要加工完这n个玩具最少需要等待的平均时间.例如加工1号玩具时间为t1,加工 ...
- Poj(3686),最小权匹配,多重匹配,KM
题目链接 The Windy's | Time Limit: 5000MS | Memory Limit: 65536K | | Total Submissions: 4939 | Accepted: ...
- poj 3686
The Windy's Time Limit: 5000MS Memory Limit: 65536K Total Submissions: 3791 Accepted: 1631 Descr ...
随机推荐
- 关于Form窗体的StartPosition 属性如何设置的问题
1.让窗体在启动时在指定位置出现 form1.StartPosition Manual CenterScreen WindowsDefaultLocation (default) WindowsDef ...
- erlang怎样有效监听大量并发连接
看了erlang的一些开源网络框架RabbitMQ.Ranch.他们都使用多个进程同一时候accept一个socket. 这样的方式在使得socketport监听的工作分担了很多其它的调度机会.可是, ...
- [PWA] 17. Cache the photo
To cache photo, You need to spreate cache db to save the photo. So in wittr example, we cache the te ...
- Android三种实现自定义ProgressBar的方式介绍
一.通过动画实现 定义res/anim/loading.xml如下: View Row Code<?xml version="1.0" encoding="UTF- ...
- ubuntu下安装tomcat和配置mysql
1.到官网 http://jakarta.apache.org/tomcat-7.0.2.tar.gz 安装文件,JDK假设已经安装完毕,接下来直接安装tomcat-7.0.2.tar.gz # ls ...
- NYOJ2括号配对问题
括号配对是最基本的栈的问题,它是栈入门的经典题目,思路是,如果是左括号直接进栈,如果是右括号,这时就要比较栈顶的元素与他是否匹配,如果匹配则出栈,否则进栈,下面是代码的实现: #include < ...
- Core Python Notes
开发需要在读 Python 核心编程,一些 Point 记录如下. ******************************************** 版本相关 标准版的 Python 是用 C ...
- 经验分享:CSS浮动(float,clear)通俗讲解(转载)
很早以前就接触过CSS,但对于浮动始终非常迷惑,可能是自身理解能力差,也可能是没能遇到一篇通俗的教程. 前些天小菜终于搞懂了浮动的基本原理,迫不及待的分享给大家. 写在前面的话: 由于CSS内容比较多 ...
- AES对称加密算法
package cn.jsonlu.passguard.utils; import org.apache.commons.codec.binary.Base64; import javax.crypt ...
- web.xml配置详解 (及<context-param>配置作用 )
http://blog.csdn.net/guihaijinfen/article/details/8363839 <context-param>配置作用 http://blog.csdn ...