题目链接: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. Java中实现对象的比较:Comparable接口和Comparator接口

    在实际应用中,我们往往有需要比较两个自定义对象大小的地方.而这些自定义对象的比较,就不像简单的整型数据那么简单,它们往往包含有许多的属性,我们一般都是根据这些属性对自定义对象进行比较的.所以Java中 ...

  2. 【POJ2886】【线段树】Who Gets the Most Candies?

    Description N children are sitting in a circle to play a game. The children are numbered from 1 to N ...

  3. spring配置中引入properties

    <context:property-placeholder location="classpath*:db.properties" />

  4. Mobile开发之meta篇

    Mobile开发之meta篇 <meta name="viewport" content="width=device-width, initial-scale=1, ...

  5. jsonp是什么以及jsonp的使用

    1概述 Jsonp(JSON with Padding)是资料格式 json 的一种“使用模式”,可以让网页从别的网域获取资料.由于同源策略,一般来说位于 server1.example.com 的网 ...

  6. Android获取相册图片

    1. AlertDialog的使用 2. 显示和隐式意图的区别 3. 相册页面的跳转 4. 选择完成后返回图片的获取 ----------------------------------------- ...

  7. Title of live Writer

    Test From Windows Live Writer **markdown bold**

  8. C# mvc3 mvc4 伪静态及IIS7.5配置

    mvc3 mvc4路由配置 //单独路由 routes.MapRoute(    name: "XXX",    url: "Home/XXX.html/{id}&quo ...

  9. 转:Win7 IIS7应用PHP Manager使用FastCGI通道快速部署PHP支持

    原文来自于:http://www.jb51.net/os/windows/62390.html 正常情况下,我们在Windows系统中部署WEB服务器(iis)支持PHP是采用ISAPI通道.参照这篇 ...

  10. 关于 Boolean 的转换

    前端经常喜欢这样写 if else if(value) { //do something } javascript 能智能的把任何类型的 value 转换成 boolean 来进行 if 判断 转换是 ...