uva 11613 - Acme Corporation(最小费用流)
来源:互联网 发布:久石让 知乎 编辑:程序博客网 时间:2024/05/01 07:50
Problem I
Acme Corporation
Input: Standard Input
Output: Standard Output
Wile E. Coyote is back. He is back in the business. The business of capturing the road runner. Being the most loyal customer to the Acme Corporation, they are hoping to do some great business with him. Although, Acme makes literally every kinds of devices, all of them has a similarity, that has been kept secret for ages. All of their products use a secret element “element X” (this is kept so secret that, only you and the Acme people know about this). The decision makers of the Acme Corp. has already estimated the maximum amount of element X that can be used into manufacture every month.
For month i, the per unit manufacturing cost of “element X” ismi, and at most niunits can be produced. Moreover, the selling price for “element X” for that month ispi. One more thing is that, element X older thanEi months can not be used. But good thing is that, they can store any amount of element X in their inventory (it's the Acme Corp, they can make anything :) ). Now, Acme Corporation wants to know how much element X should be produced and sold, to make the highest amount of profit.
Input
l First line contains T, the number of test cases.
l For each test case
u First line contains two integers M and I, the number of months to consider and the cost of storing per unit of element X per month in the inventory.
u Each of the next M lines describe the parameters for each month
· The ith line contains 5 integers, mi, ni, pi, si, Ei, wheremi is the per unit manufacturing cost for monthi, ni is the maximum amount that can be manufactured in this month,pi is the selling price for that month(per unit),si is the maximum amount that can be sold that month, andEi is the maximum time,element X manufactured on monthi, can be stored in the inventory. For example, if for month 1, E1 = 3, the elements produced in month 1 can be sold in months 1, 2, 3 and 4. But it can not be sold in month 5.
Output
For each test case, output the case number and the maximum amount of profit, Acme Corporation can make. Note that, you have to think of onlyM months. If any amount of element X is stored in the inventory after this period, are completely ignored. For formatting, see the sample input and output.
Constraints
l
l
l
l
Sample Input Output for Sample Input
1
2 2
2 10 3 20 2
10 100 7 5 2
Case 1: 2
Problem Setter: Manzurur Rahman Khan
Special Thanks: Md. Arifuzzaman Arif
书本上的例题,就是求最大利润,转化为最小费用流的题目。
最小费用流的问题可以用最小费用最大流来解,只要在增广的值大于0时break即可。
下面是LRJ的代码
// UVa11613 Acme Corporation// Rujia Liu#include<cstdio>#include<cstring>#include<queue>#include<vector>#include<algorithm>#include<cassert>using namespace std;const int maxn = 202 + 10;const int INF = 1000000000;typedef long long LL;struct Edge { int from, to, cap, flow, cost;};struct MCMF { int n, m, s, t; vector<Edge> edges; vector<int> G[maxn]; int inq[maxn]; // 是否在队列中 int d[maxn]; // Bellman-Ford int p[maxn]; // 上一条弧 int a[maxn]; // 可改进量 void init(int n) { this->n = n; for(int i = 0; i < n; i++) G[i].clear(); edges.clear(); } void AddEdge(int from, int to, int cap, int cost) { edges.push_back((Edge){from, to, cap, 0, cost}); edges.push_back((Edge){to, from, 0, 0, -cost}); m = edges.size(); G[from].push_back(m-2); G[to].push_back(m-1); } bool BellmanFord(int s, int t, LL& ans) { for(int i = 0; i < n; i++) d[i] = INF; memset(inq, 0, sizeof(inq)); d[s] = 0; inq[s] = 1; p[s] = 0; a[s] = INF; queue<int> Q; Q.push(s); while(!Q.empty()) { int u = Q.front(); Q.pop(); inq[u] = 0; for(int i = 0; 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] = 1; } } } } if(d[t] > 0) return false;//Attention!!!!!!!!! ans += (LL)d[t] * (LL)a[t]; int u = t; while(u != s) { edges[p[u]].flow += a[t]; edges[p[u]^1].flow -= a[t]; u = edges[p[u]].from; } return true; } // 需要保证初始网络中没有负权圈 LL Mincost(int s, int t) { LL cost = 0; while(BellmanFord(s, t, cost)); return cost; }};MCMF g;int main() { int T, month, store_cost; scanf("%d", &T); for(int kase = 1; kase <= T; kase++) { scanf("%d%d", &month, &store_cost); g.init(2*month+2); int source = 0, sink = 2*month+1; for(int i = 1; i <= month; i++) { int make_cost, make_limit, price, sell_limit, max_store; scanf("%d%d%d%d%d", &make_cost, &make_limit, &price, &sell_limit, &max_store); g.AddEdge(source, i, make_limit, make_cost); g.AddEdge(month+i, sink, sell_limit, -price); // 收益是负费用 for(int j = 0; j <= max_store; j++) if(i + j <= month) g.AddEdge(i, month+i+j, INF, store_cost * j); // 存j个月以后卖 } printf("Case %d: %lld\n", kase, -g.Mincost(source, sink)); } return 0;}
- UVA - 11613 Acme Corporation(最小费用流)
- uva 11613 - Acme Corporation(最小费用流)
- uva 11613 Acme Corporation(费用流)
- UVA - 11613 Acme Corporation(任意流最小费用)
- UVa11613 Acme Corporation(最小费用流)
- UVA 11613 Acme Corporation(不固定流量的最小费用流)
- UVA 11613 Acme Corporation(不固定流量的最小费用流)
- UVA 11613 Acme Corporation
- UVA 11613 Acme Corporation
- uva11613 - Acme Corporation 费用流
- 不固定流量的最小费用流 生产销售规划 uva11613 - Acme Corporation
- Acme Corporation UVA
- uva 1486 - Transportation(最小费用流)
- UVA 10888 - Warehouse(最小费用流)
- 最小费用流: uva 1658
- uva 10806 - Dijkstra, Dijkstra.(最小费用流)
- uva 1317 - Concert Hall Scheduling(最小费用最大流)
- uva 12092 - Paint the Roads(最小费用最大流)
- asp.net备份还原数据库
- 自我激励的方法
- Android之URI
- ava项目导出jar包,引入第三方jar包。
- [转载]如何分析 kernel panic
- uva 11613 - Acme Corporation(最小费用流)
- UVA 11553 - Grid Game
- opencv-Mat
- 通过uCOS-II的邮箱方式,实现任务间数据传递的简单实例
- PHP 单例模式
- android rhino
- 磁共振实验数据SPM8处理流程(待续)
- HP大中华区总裁孙振耀退休感言
- vxWorks上ifShow、ping组件位置