题目链接:http://acm.hust.edu.cn/vjudge/problem/viewProblem.action?id=33452

【思路】

最小费用流。

构图:

1 每个月建立2个点,建立st点

2 相应连边,代价cost为正,盈利cost为负。

跑最小费用流,即当费用大于0时停止最短路增广。即在满足相应流量的限制下不要求流量,只要求费用最小。

【代码】

 #include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#define FOR(a,b,c) for(int a=(b);a<(c);a++)
using namespace std; typedef long long LL ;
const int maxn = +;
const int INF = 1e9; struct Edge{ int u,v,cap,flow,cost;
}; struct MCMF {
int n,m,s,t;
int inq[maxn],a[maxn],d[maxn],p[maxn];
vector<int> G[maxn];
vector<Edge> es; void init(int n) {
this->n=n;
es.clear();
for(int i=;i<n;i++) G[i].clear();
}
void AddEdge(int u,int v,int cap,int cost) {
es.push_back((Edge){u,v,cap,,cost});
es.push_back((Edge){v,u,,,-cost});
m=es.size();
G[u].push_back(m-);
G[v].push_back(m-);
} bool SPFA(int s,int t,int& flow,LL& cost) {
for(int i=;i<n;i++) d[i]=INF;
memset(inq,,sizeof(inq));
d[s]=; inq[s]=; p[s]=; a[s]=INF;
queue<int> q; q.push(s);
while(!q.empty()) {
int u=q.front(); q.pop(); inq[u]=;
for(int i=;i<G[u].size();i++) {
Edge& e=es[G[u][i]];
int v=e.v;
if(e.cap>e.flow && d[v]>d[u]+e.cost) {
d[v]=d[u]+e.cost;
p[v]=G[u][i];
a[v]=min(a[u],e.cap-e.flow); //min(a[u],..)
if(!inq[v]) { inq[v]=; q.push(v);
}
}
}
}
if(d[t]>) return false;
flow+=a[t] , cost+=(LL) a[t]*d[t];
for(int x=t; x!=s; x=es[p[x]].u) {
es[p[x]].flow+=a[t]; es[p[x]^].flow-=a[t];
}
return true;
}
int Mincost(int s,int t,LL& cost) {
int flow=; cost=;
while(SPFA(s,t,flow,cost)) ;
return flow;
}
} mc; int M,I,m,n,p,s,E; int main() {
int T,kase=;
scanf("%d",&T);
while(T--) {
scanf("%d%d",&M,&I);
int start=M*,end=start+;
mc.init(M*+);
FOR(i,,M) {
scanf("%d%d%d%d%d",&m,&n,&p,&s,&E);
mc.AddEdge(start,i,n,m);
mc.AddEdge(M+i,end,s,-p);
FOR(j,,E+)
if(i+j<M) mc.AddEdge(i,M+i+j,INF,I*j);
}
int flow; LL cost;
flow=mc.Mincost(start,end,cost);
printf("Case %d: %lld\n",++kase,-cost);
}
return ;
}

UVa11613 Acme Corporation(最小费用流)的更多相关文章

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

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

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

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

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

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

  4. UVA11613 Acme Corproation

    UVA11613 Acme Corproation 生产销售计划 题目大意 A公司生产一种元素,给出该元素在未来M个月中每个月的单位售价,最大生产量,生产成本,最大销售量和最大存储时间,和每月存储代价 ...

  5. UVA 11613 Acme Corporation(不固定流量的最小费用流)

    题意好长....变量好多.... 增加源点跟汇点.然后将每个月份看成一个点,然后拆成两个点u 跟 u+n. 从s向每个u连一条<n[u], m[i]>的弧,表示最多生产量及价值. 从每个u ...

  6. Acme Corporation UVA - 11613 费用流

    Code: #include<cstdio> #include<cstring> #include<vector> #include<queue> #i ...

  7. OC编程之道-创建对象之抽象工厂方法

    定义:提供一个创建一系列相关或相互依赖对象的接口,而无需指定他们具体的类.       <AbstractProductA> <AbstractProductB> <Ab ...

  8. jquery mobile validation

    <!DOCTYPE html> <html> <head> <meta http-equiv="content-type" content ...

  9. From MSI to WiX, Part 2 - ARP support, by Alex Shevchuk

    Following content is directly reprinted from From MSI to WiX, Part 2 - ARP support Author: Alex Shev ...

随机推荐

  1. .net 使用AjaxControlToolkit.dll 遇到的"Sys"未定义问题

    1.配置文件一般都会缺少<httpHandlers></httpHandlers> 这一段, <httpHandlers> <remove verb=&quo ...

  2. php函数serialize()与unserialize()

    serialize()和unserialize()在php手册上的解释是: serialize — Generates a storable representation of a value ser ...

  3. head标签

    1.head标签中有个<meta>,,个人理解知识,可以设置页面字符集,文本格式,还可以加一些注释,例如如下所示

  4. 用java写bp神经网络(三)

    孔子曰,吾日三省吾身.我们如果跟程序打交道,除了一日三省吾身外,还要三日一省吾代码.看代码是否可以更简洁,更易懂,更容易扩展,更通用,算法是否可以再优化,结构是否可以再往上抽象.代码在不断的重构过程中 ...

  5. jQuery 效果 - 淡入淡出

    通过 jQuery,您可以实现元素的淡入淡出效果. 点击展示 淡入/淡出 面板 实例 jQuery fadeIn()演示 jQuery fadeIn() 方法. jQuery fadeOut()演示 ...

  6. ZendStudio快捷键

    Ctrl+1 快速修复(最经典的快捷键,就不用多说了)Ctrl+D: 删除当前行Ctrl+Alt+↓ 复制当前行到下一行(复制增加)Ctrl+Alt+↑ 复制当前行到上一行(复制增加)Alt+↓ 当前 ...

  7. TestNG目录

    1 - 简介  2 - 注解  3 - testng.xml  4 - 执行 TestNG  5 - 测试方法, 测试类 和 测试组    5.1 - 测试方法    5.2 - 测试组    5.3 ...

  8. Sql Server 时间格式

    问题引出: Sql Server 里 dateTime 数据类型,会精确到毫秒.如果我们 在插入一条数据的时候,使用 GetDate() 记录 这个记录插入的时间,则会插入当前时间,精确到毫秒.在查询 ...

  9. js基础 - 兼容代码

    js基础 - 兼容代码 . scrollTop . chrome document.body.scrollTop . IE && firefox document.documentEl ...

  10. 如何将eclipse里的项目发布到github

    首先,给eclipse安装上EGit 在“Help > Install new software”中添加 http://download.eclipse.org/egit/updates 两个都 ...