UVA11613 Acme Corporation —— 最小费用流(流量不固定的最小费用流)
题目链接:https://vjudge.net/problem/UVA-11613
题意:
商品X在第i个月内:生产一件需要花费mi元,最多可生产ni件,销售一件(在这个月内销售,而不管它是在那个月生产的)的价格是pi元, 最多能销售si件, 在这个月生产的产品的保质期为Ei。对于所有商品X,每“保质”一个月,就要花费I元。问:在M个月内,最多能获利多少?
题解:
最小费用流问题,建图方式如下(详情在《训练指南》P367):
1.把每个月拆成两个点,一个点为生产,另一个点为销售。
2.如果月x生产的商品能够放到月y内销售,就在月x的生产点和月y的销售点之间连一条边,容量为月x的最大生产量, 花费为0。
3.建立超级源点,并且连向每个月的生产点,边的容量为该月的最大生产量, 边的花费为该月生产一件商品所需的花费。
4.建立超级汇点,并且连向每个月的销售点,边的容量为该月的最大销售量, 边的花费为该月单间商品的售价的负值。
5.跑最小费用流算法:当增广得到的单位费用和小于0时,表明收入大于敷出(因为收入在图中设置为负值),继续增广;当单位费用和大于等于0时,表明收入小于敷出,再继续增广,利润反而降低,所以在此时就应该停止增广。
代码如下:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <set>
using namespace std;
typedef long long LL;
const int INF = 2e9;
const LL LNF = 9e18;
const int mod = 1e9+;
const int MAXM = 1e5+;
const int MAXN = 2e2+; struct Edge
{
int to, next, cap, flow, cost;
}edge[MAXM];
int tot, head[MAXN];
int pre[MAXN], dis[MAXN];
bool vis[MAXN];
int N; void init(int n)
{
N = n;
tot = ;
memset(head, -, sizeof(head));
} void add(int u, int v, int cap, int cost)
{
edge[tot].to = v; edge[tot].cap = cap; edge[tot].cost = cost;
edge[tot].flow = ; edge[tot].next = head[u]; head[u] = tot++;
edge[tot].to = u; edge[tot].cap = ; edge[tot].cost = -cost;
edge[tot].flow = ; edge[tot].next = head[v]; head[v] = tot++;
} bool spfa(int s, int t)
{
queue<int>q;
for(int i = ; i<N; i++)
{
dis[i] = INF;
vis[i] = false;
pre[i] = -;
} dis[s] = ;
vis[s] = true;
q.push(s);
while(!q.empty())
{
int u = q.front();
q.pop();
vis[u] = false;
for(int i = head[u]; i!=-; i = edge[i].next)
{
int v = edge[i].to;
if(edge[i].cap>edge[i].flow && dis[v]>dis[u]+edge[i].cost)
{
dis[v] = dis[u]+edge[i].cost;
pre[v] = i;
if(!vis[v])
{
vis[v] = true;
q.push(v);
}
}
}
}
if(pre[t]==-) return false;
if(dis[t]>=) return false; //当单位费用和大于等于0时,即停止增广
return true;
} int minCostMaxFlow(int s, int t, LL &cost)
{
int flow = ;
cost = ;
while(spfa(s,t))
{
int Min = INF;
for(int i = pre[t]; i!=-; i = pre[edge[i^].to])
{
if(Min>edge[i].cap-edge[i].flow)
Min = edge[i].cap-edge[i].flow;
}
for(int i = pre[t]; i!=-; i = pre[edge[i^].to])
{
edge[i].flow += Min;
edge[i^].flow -= Min;
cost += 1LL*edge[i].cost*Min;
}
flow += Min;
}
return flow;
} int main()
{
int T, M, I;
scanf("%d", &T);
for(int kase = ; kase<=T; kase++)
{
scanf("%d%d", &M, &I);
int start = , end = *M+;
init(*M+); for(int i = ; i<=M; i++)
{
int m, n, p, s, E;
scanf("%d%d%d%d%d", &m,&n,&p,&s,&E);
add(start, i, n, m);
for(int j = i; j<=min(M, i+E); j++)
add(i, M+j, n, (j-i)*I);
add(M+i, end, s, -p);
} LL min_cost;
minCostMaxFlow(start, end, min_cost);
printf("Case %d: %lld\n", kase, -min_cost);
}
}
UVA11613 Acme Corporation —— 最小费用流(流量不固定的最小费用流)的更多相关文章
- UVa11613 Acme Corporation(最小费用流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33452 [思路] 最小费用流. 构图: 1 每个月建立2个点,建立 ...
- UVA-11613 Acme Corporation (最大费用最大流+拆点)
题目大意:有一种商品X,其每每单位存放一个月的代价I固定.并且已知其每月的最大生产量.生产每单位的的代价.最大销售量和销售单价,还已知每个月生产的X能最多能存放的时间(以月为单位).问只考虑前m个月, ...
- Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负
/** 题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负 链接:https://vjudge.net/problem/UVA-1161 ...
- UVA11613 Acme Corproation
UVA11613 Acme Corproation 生产销售计划 题目大意 A公司生产一种元素,给出该元素在未来M个月中每个月的单位售价,最大生产量,生产成本,最大销售量和最大存储时间,和每月存储代价 ...
- UVA 11613 Acme Corporation(不固定流量的最小费用流)
题意好长....变量好多.... 增加源点跟汇点.然后将每个月份看成一个点,然后拆成两个点u 跟 u+n. 从s向每个u连一条<n[u], m[i]>的弧,表示最多生产量及价值. 从每个u ...
- Acme Corporation UVA - 11613 费用流
Code: #include<cstdio> #include<cstring> #include<vector> #include<queue> #i ...
- 【UVA11613 训练指南】生产销售规划 【费用流】
题意: Acme公司生产一种X元素,给出该元素在未来M个月中每个月的单位售价.最大产量.最大销售量,以及最大储存时间(过期报废不过可以储存任意多的量).你的任务是计算出公司能够赚到的最大利润. 分析: ...
- UVa1658 Admiral(拆点法+最小费用流)
题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=51253 [思路] 固定流量的最小费用流. 拆点,将u拆分成u1和u ...
- Going Home (hdu 1533 最小费用流)
集训的图论都快结束了,我才看懂了最小费用流,惭愧啊. = = 但是今天机械键盘到了,有弄好了自行车,好高兴\(^o^)/~ 其实也不是看懂,就会套个模板而已.... 这题最重要的就是一个: 多组输入一 ...
随机推荐
- STL学习笔记(四) 迭代器
条款26:iterator 优先于 const_iterator, reverse_iterator, const_reverse_iterator iterator, reverse_iterato ...
- hdu - 3594 Cactus (强连通)
http://acm.hdu.edu.cn/showproblem.php?pid=3594 判断给定的图是否是强连通的,并且每条边都只属于一个连通分量. 判断强连通只需要判断缩点之后顶点数是否为1即 ...
- (5)ASP.NET Core 中的静态文件
1.前言 当我们创建Core项目的时候,Web根目录下会有个wwwroot文件目录,wwwroot文件目录里面默认有HTML.CSS.IMG.JavaScript等文件,而这些文件都是Core提供给客 ...
- pinpoint 应用性能管理工具安装部署
原文:http://www.cnblogs.com/yyhh/p/6106472.html pinpoint 安装部署 阅读目录 1. 环境配置 1.1 获取需要的依赖包 1.2 配置jdk1.7 ...
- 最新的hustoj搭建姿势
试着照某度上的教程搭了一下hustoj,出了一些问题,之前的搭建姿势很多已经不适用了,重新整理一下思路,方法二简单粗暴: 方法一: 首先虚拟机安装了Elementory OS (基于Ubuntu的衍生 ...
- js加入收藏夹
工作需要了解了一下点击加入收藏这个功能 <script> function _addFavorite() { var url = window.location; //获取当前网页网址 v ...
- c++面试题总结(4)
一.找错题 试题1: void test1() { ]; "; strcpy( string, str1 ); } 试题2: void test2() { ],str1[]; int i; ...
- CPU Stepping
http://baike.baidu.com/view/16839.htm?fr=ala0_1_1 步进 编辑 步进(Stepping)是CPU的一个重要参数,也叫分级鉴别产品数据转换规范,“步进 ...
- HDU 3342 Legal or Not (最短路 拓扑排序?)
Legal or Not Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Tota ...
- FastDFS的配置、部署与API使用解读(1)Get Started with FastDFS(转)
转载请注明来自:诗商·柳惊鸿CSDN博客,原文链接:FastDFS的配置.部署与API使用解读(1)入门使用教程 1.背景 FastDFS是一款开源的.分布式文件系统(Distributed File ...