UVA11613 Acme Corproation 生产销售计划

题目大意

A公司生产一种元素,给出该元素在未来M个月中每个月的单位售价,最大生产量,生产成本,最大销售量和最大存储时间,和每月存储代价,问这家公司在M个月内所能赚大的最大利润(题意来源:http://blog.csdn.net/l123012013048/article/details/47962965)

题解

每个月拆成两个点,用于表示存储。S向X集合点连生产成本,X集合向Y集合连存储成本,Y集合向T连收益。

跑最小费用流。不要求最大流。

不(书)难(上)发(写)现(道),d[T]随着增广会逐渐增大,于是等d[T] >= 0,就不要继续增广了。此时得到的就是最小费用流。

第一次WA了,接着我同时完成如下事情:开大空间、变longlong、上网看输出格式有没有多空格换行……

然后A了

做UVA时间久了

踩过的坑多了去了

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <map>
#include <cmath>
inline long long max(long long a, long long b){return a > b ? a : b;}
inline long long min(long long a, long long b){return a < b ? a : b;}
inline long long abs(long long x){return x < 0 ? -x : x;}
inline void swap(long long &x, long long &y){long long tmp = x;x = y;y = tmp;}
inline void read(long long &x)
{
x = 0;char ch = getchar(), c = ch;
while(ch < '0' || ch > '9') c = ch, ch = getchar();
while(ch <= '9' && ch >= '0') x = x * 10 + ch - '0', ch = getchar();
if(c == '-') x = -x;
}
const long long INF = 0x3f3f3f3f3f3f3f3f;
struct Edge
{
long long u,v,w,c,nxt;
Edge(long long _u, long long _v, long long _w, long long _c, long long _nxt){u = _u;v = _v;w = _w;c = _c;nxt = _nxt;}
Edge(){}
}edge[1000010];
long long head[1000010], cnt = 1, S, T, q[1000010], he, ta, d[1000010], vis[1000010], from[1000010], ans;
inline void insert(long long a, long long b, long long c, long long d)
{
edge[++ cnt] = Edge(a, b, c, d, head[a]), head[a] = cnt;
edge[++ cnt] = Edge(b, a, 0, -d, head[b]), head[b] = cnt;
}
bool spfa()
{
memset(d, 0x3f, sizeof(d)), d[S] = 0, he = 0, ta = 1, q[0] = S, vis[S] = 1;
while(he < ta)
{
long long now = q[he ++];if(he > 1000000) he = 0;
for(long long pos = head[now];pos;pos = edge[pos].nxt)
{
long long v = edge[pos].v;
if(edge[pos].w && d[v] > d[now] + edge[pos].c)
{
d[v] = d[now] + edge[pos].c, from[v] = pos;
if(!vis[v])
{
q[ta ++] = v;
if(ta > 1000000) ta = 0;
}
}
}
vis[now] = 0;
}
return d[T] != INF;
}
long long flow()
{
long long mi = INF;
for(long long i = from[T];i;i = from[edge[i].u]) mi = min(mi, edge[i].w);
for(long long i = from[T];i;i = from[edge[i].u]) edge[i].w -= mi, edge[i ^ 1].w += mi, ans += edge[i].c * mi;
}
void mcf()
{
while(spfa())
{
if(d[T] >= 0) return;
flow();
}
}
long long t, n, c, cb[10000], cl[10000], dj[10000], masl[10000], mat[10000];
//n:月数
//c:存每个单位放一个月的代价
//cb[i]:每单元生产成本
//cl[i]:最大产量
//dj[i]:销售单价
//masl[i]:最大销售量
//mat[i]:储存最大时间
int main()
{
read(t);
S = 1000000, T = S + 1;
for(long long ca = 1;ca <= t;++ ca)
{
cnt = 1, ans = 0, memset(head, 0, sizeof(head));
read(n), read(c);
for(long long i = 1;i <= n;++ i)
{
read(cb[i]), read(cl[i]), read(dj[i]), read(masl[i]), read(mat[i]);
insert(S, i, cl[i], cb[i]);
insert(n + i, T, masl[i], - dj[i]);
}
for(long long i = 1;i <= n;++ i)
for(long long k = 0, j = i + k;k <= mat[i] && j <= n;++ k, ++ j)
insert(i, n + j, INF, c * k);
mcf();
printf("Case %lld: %lld\n", ca, -ans);
}
return 0;
}

UVA11613 Acme Corproation的更多相关文章

  1. UVA11613 Acme Corporation —— 最小费用流(流量不固定的最小费用流)

    题目链接:https://vjudge.net/problem/UVA-11613 题意: 商品X在第i个月内:生产一件需要花费mi元,最多可生产ni件,销售一件(在这个月内销售,而不管它是在那个月生 ...

  2. UVa11613 Acme Corporation(最小费用流)

    题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33452 [思路] 最小费用流. 构图: 1 每个月建立2个点,建立 ...

  3. UVA-11613 Acme Corporation (最大费用最大流+拆点)

    题目大意:有一种商品X,其每每单位存放一个月的代价I固定.并且已知其每月的最大生产量.生产每单位的的代价.最大销售量和销售单价,还已知每个月生产的X能最多能存放的时间(以月为单位).问只考虑前m个月, ...

  4. Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负

    /** 题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负 链接:https://vjudge.net/problem/UVA-1161 ...

  5. 安装VC6提示找不到ACME时的解决办法

    将安装程序COPY到电脑上1.打开setupwiz.ini,把"acme=acmboot.exe"改为"=acmsetup.exe";2.STF=setup/v ...

  6. minihttp http://www.acme.com/software/mini_httpd/

    1.安装mini_httpd 1.1把下载的mini_httpd-1.19.tar.gz拷贝到根目录   1.2 解压tar -xvfzmini_httpd-1.19.tar.gz ,会在根目录产生一 ...

  7. debian8下acme nginx 部署记录

    1.更新源 apt update 2.安装curl git apt install curl git -y 3.克隆acme仓库 curl https://get.acme.sh | sh git c ...

  8. 使用 acme.sh 签发续签 Let‘s Encrypt 证书 泛域名证书

    1. 安装 acme.sh 安装很简单, 一个命令: curl https://get.acme.sh | sh 并创建 一个 bash 的 alias, 方便你的使用 alias acme.sh=~ ...

  9. Linux下使用acme.sh 配置https 免费证书

    acme.sh 简单来说acme.sh 实现了 acme 协议, 可以从 let‘s encrypt 生成免费的证书.acme.sh 有以下特点:一个纯粹用Shell(Unix shell)语言编写的 ...

随机推荐

  1. POJ 2074 /// 判断直线与线段相交 视野盲区

    题目大意: 将所有物体抽象成一段横向的线段 给定房子的位置和人行道的位置 接下来给定n个障碍物的位置 位置信息为(x1,x2,y) 即x1-x2的线段 y相同因为是横向的 求最长的能看到整个房子的一段 ...

  2. Bootstrap——可拖动模态框(Model)

    还是上一个小项目,o(╥﹏╥)o,要实现点击一个div或者button或者一个东西然后可以弹出一个浮在最上面的弹框.网上找了找,发现Bootstrap的Model弹出框可以实现该功能,因此学习了一下, ...

  3. (转)Windows中杀死占用某个端口的进程

    启动tomcat时候,控制台报错,发现是端口占用,于是寻找方法关闭对应的程序. 从网上找了好久,尝试之后,发现不行.开始自己尝试,终于,成功的将占用端口的进程杀掉.在此记录下过程(以8081端口为例) ...

  4. uoj37 主旋律

    题意:一个班级n个人,如果a爱b,那么a->b一条有向边.问有多少种删边集合使得图仍然强联通? n<=15.   标程: #include<cstdio> #include&l ...

  5. LeetCode第一题—— Two Sum(寻找两数,要求和为target)

    题目描述: Given an array of integers, return indices of the two numbers such that they add up to a speci ...

  6. commons lang3的StringUtils中isEmpty()方法和isBlank()方法的区别

    先给结论: 1. StringUtils.isEmpty()中的空格作非空处理2. StringUtils.isNotEmpty()是StringUtils.isEmpty()取反后的结果3. Str ...

  7. 如何将数组2对象中的属性push进数组1的对象中去,组合成新的数组

  8. 莫烦pytorch学习笔记(八)——卷积神经网络(手写数字识别实现)

    莫烦视频网址 这个代码实现了预测和可视化 import os # third-party library import torch import torch.nn as nn import torch ...

  9. LocalSessionFactoryBean有几个属性查找hibernate映射文件

    LocalSessionFactoryBean有几个属性查找hibernate映射文件: mappingResources.mappingLocations.mappingDirectoryLocat ...

  10. LOJ10157——皇宫看守(树形DP)

    传送门:QAQQAQ 题意:在一个树上放置守卫,使每一个节点都至少有相邻一节点放置守卫,使最终经费最少 思路:树形DP 首先会想到没有上司的舞会,0表示不放守卫,1表示放守卫,但考虑到对于当前点不放守 ...