/**
题目:Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负
链接:https://vjudge.net/problem/UVA-11613
题意:m个月生产销售商品,求获得的最大利润。具体细节。
第i个月生产一件商品费用为mi,可以最多生产ni件,卖出一件商品价格为pi,最多卖出si件, 该月生产的商品
最多可以可以存放ei个月,即:i+1<= x <= i+ei 就是可以保存的时间,在该时间内可以拿出来卖。
每件商品储存一个月的费用为I。如果m个月之后,还有商品没卖出,那么那些商品舍弃,不产生利润。
思路:拆点法+最大费用最大流(费用取相反数)+费用有正负 由于求最大利润, 所以生产费用和售价都取相反数
月份i拆成i,i'。 s->i,cap = ni, cost = mi。 i'->t, cap=si, cost = -pi。 i->i', cap = INF, cost = 0; 如果月份x,y。 x+ex<=y。那么x->y', cap = INF, cost = I*(y-x)。 即:x月份生产的商品可以留到y月份来卖。 由于取了相反数,所以得到的解越小,那么我们得到的利润越大。所以当增广路上的费用和>=0时候,舍去该增广路。
*/
#include<iostream>
#include<cstring>
#include<vector>
#include<map>
#include<cstdio>
#include<algorithm>
#include<queue>
using namespace std;
const int INF = 0x3f3f3f3f;
typedef long long LL;
const int N = ;
struct Edge{
int from, to, cap, flow, cost;
Edge(int u,int v,int c,int f,int w):from(u),to(v),cap(c),flow(f),cost(w){}
};
struct MCMF{
int n, m;
vector<Edge> edges;
vector<int> G[N];
int inq[N];
int d[N];
int p[N];
int a[N]; void init(int n){
this->n = n;
for(int i = ; i <= n; i++) G[i].clear();
edges.clear();
} void AddEdge(int from,int to,int cap,long long cost){
edges.push_back(Edge(from,to,cap,,cost));
edges.push_back(Edge(to,from,,,-cost));
m = edges.size();
G[from].push_back(m-);
G[to].push_back(m-);
} bool BellmanFord(int s,int t,int &flow,long long &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 = edges[G[u][i]];
if(e.cap>e.flow&&d[e.to]>d[u]+e.cost){
d[e.to] = d[u]+e.cost;
p[e.to] = G[u][i];
a[e.to] = min(a[u],e.cap-e.flow);
if(!inq[e.to]) {Q.push(e.to); inq[e.to] = ;}
}
}
}
if(d[t]==INF) return false;
if(d[t]>=){///当增广路上的费用和>=0时候,舍去该增广路。
return false;
}
flow += a[t];
cost += (long long)d[t]*(long long)a[t];
for(int u = t; u!=s; u = edges[p[u]].from){
edges[p[u]].flow+=a[t];
edges[p[u]^].flow-=a[t];
}
return true;
}
int MincostMaxflow(int s,int t,long long &cost){
int flow = ;
cost = ;
while(BellmanFord(s,t,flow,cost));
return flow;
}
};
int main()
{
int T, m, I, cas=;
cin>>T;
while(T--)
{
scanf("%d%d",&m,&I);
int s = , t = *m+;
MCMF mcmf;
mcmf.init(t);
int mi, ni, pi, si, ei;
for(int i = ; i <= m; i++){
scanf("%d%d%d%d%d",&mi,&ni,&pi,&si,&ei);
mcmf.AddEdge(s,i,ni,mi);
mcmf.AddEdge(i+m,t,si,-pi);
mcmf.AddEdge(i,i+m,INF,);
for(int j = ; j <= ei&&i+j<=m; j++){
mcmf.AddEdge(i,i+j+m,INF,I*j);
}
}
long long cost;
int flow = mcmf.MincostMaxflow(s,t,cost);
printf("Case %d: %lld\n",cas++,-cost);
}
return ;
}

Acme Corporation UVA - 11613 拆点法+最大费用最大流(费用取相反数)+费用有正负的更多相关文章

  1. Acme Corporation UVA - 11613 费用流

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

  2. UVa 1658 (拆点法 最小费用流) Admiral

    题意: 给出一个有向带权图,求从起点到终点的两条不相交路径使得权值和最小. 分析: 第一次听到“拆点法”这个名词. 把除起点和终点以外的点拆成两个点i和i',然后在这两点之间连一条容量为1,费用为0的 ...

  3. Risk UVA - 12264 拆点法+最大流+二分 最少流量的节点流量尽量多。

    /** 题目:Risk UVA - 12264 链接:https://vjudge.net/problem/UVA-12264 题意:给n个点的无权无向图(n<=100),每个点有一个非负数ai ...

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

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

  5. 【BZOJ-2893】征服王 最大费用最大流(带下界最小流)

    2893: 征服王 Time Limit: 10 Sec  Memory Limit: 256 MBSubmit: 156  Solved: 48[Submit][Status][Discuss] D ...

  6. hdu 4411 2012杭州赛区网络赛 最小费用最大流 ***

    题意: 有 n+1 个城市编号 0..n,有 m 条无向边,在 0 城市有个警察总部,最多可以派出 k 个逮捕队伍,在1..n 每个城市有一个犯罪团伙,          每个逮捕队伍在每个城市可以选 ...

  7. 【BZOJ】1221: [HNOI2001] 软件开发(最小费用最大流)

    http://www.lydsy.com/JudgeOnline/problem.php?id=1221 先吐槽一下,数组依旧开小了RE:在spfa中用了memset和<queue>的版本 ...

  8. 【bzoj2661】[BeiJing wc2012]连连看 最大费用最大流

    题目描述 凡是考智商的题里面总会有这么一种消除游戏.不过现在面对的这关连连看可不是QQ游戏里那种考眼力的游戏.我们的规则是,给出一个闭区间[a,b]中的全部整数,如果其中某两个数x,y(设x>y ...

  9. POJ - 2516 Minimum Cost(最小费用最大流)

    1.K种物品,M个供应商,N个收购商.每种物品从一个供应商运送到一个收购商有一个单位运费.每个收购商都需要K种物品中的若干.求满足所有收购商需求的前提下的最小运费. 2.K种物品拆开来,分别对每种物品 ...

随机推荐

  1. 【Docker】利用数据卷容器来备份、恢复、迁移数据卷

    利用数据卷容器来备份.恢复.迁移数据卷 可以利用数据卷对其中的数据进行进行备份.恢复和迁移. 备份 首先使用 --volumes-from 标记来创建一个加载 dbdata 容器卷的容器,并从主机挂载 ...

  2. 使用rsync进行多服务器同步

    使用rsync进行多服务器同步 @(Others) 当集群数量很大时,修改配置文件和节点之间的文件同步是一件很麻烦且浪费时间的事情. rsync是linux上实现不同机器之间文件同步.备份的工具,ce ...

  3. ubuntu 不是 识别 android 设备 解决方法

    ubuntu: 在终端输入lsusb: langu@langu:~$ lsusb Bus 001 Device 001: ID 1d6b:0002 Linux Foundation 2.0 root ...

  4. MVC工作原理

    MVC(Model-View-Controller,模型—视图—控制器模式)用于表示一种软件架构模式.它把软件系统分为三个基本部分:模型(Model),视图(View)和控制器(Controller) ...

  5. [Algorithom] Shuffle an array

    Shuffling is a common process used with randomizing the order for a deck of cards. The key property ...

  6. 程序的入口及AppDelegate窗体显示原理

    AppDelegate.m - (void)dealloc { [_window release]; [super dealloc]; } - (BOOL)application:(UIApplica ...

  7. IIS 之 Asp.Net项目内部运行详解

    我们都知道,当用户在浏览器地址栏中输入网址时,该请求会被IIS服务器捕获,如果是请求的是静态页面则由IIS本身处理并直接返回客户端:如果是动态页(*.aspx),通过一系列的前期的处理来到 .NET ...

  8. 为什么要用 SpringMVC 的 SessionStatus

    我们可以在需要访问 Session 属性的 controller 上加上 @SessionAttributes,然后在 action 需要的 User 参数上加上 @ModelAttribute,并保 ...

  9. Codeigniter 使用 Mysql 存储过程

    本篇文章由:http://xinpure.com/codeigniter-using-mysql-stored-procedures/ 执行存储过程 $query = $this -> db - ...

  10. jBoss修改端口号

    http://blog.csdn.net/ghost_t/article/details/5708991 jBoss版本: jboss-5.1.0.GA jboss-6.0.0.Final     j ...