uva 11613 不固定流量负费用最小费用最大流
2013-09-21 23:14
369 查看
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” is mi,
and at most ni units can be produced. Moreover, the
selling price for “element X” for that month is pi.
One more thing is that, element X older than Ei 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, where mi
is the per unit manufacturing cost for month i, 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, and Ei
is the maximum time,element X manufactured on month i, 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 only M 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
Problem
Setter: Manzurur Rahman Khan
Special
Thanks: Md. Arifuzzaman Arif
抄自白书,建模如下:
添加源点s,汇点t,每个月有两个点表示i,i',再建立源点s和汇点t。源点i向每个点i连一条边,容量表示第i个月的产量:每个点i'到汇点连一条边,表示第i个月的销量。每个点i向点i',(i+1)', (i+2)'、、、连一条边,表示存储0,1,2,。。。个月以后卖掉。各弧费用与成本成正比。
AC代码:
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” is mi,
and at most ni units can be produced. Moreover, the
selling price for “element X” for that month is pi.
One more thing is that, element X older than Ei 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, where mi
is the per unit manufacturing cost for month i, 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, and Ei
is the maximum time,element X manufactured on month i, 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 only M 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 |
Setter: Manzurur Rahman Khan
Special
Thanks: Md. Arifuzzaman Arif
抄自白书,建模如下:
添加源点s,汇点t,每个月有两个点表示i,i',再建立源点s和汇点t。源点i向每个点i连一条边,容量表示第i个月的产量:每个点i'到汇点连一条边,表示第i个月的销量。每个点i向点i',(i+1)', (i+2)'、、、连一条边,表示存储0,1,2,。。。个月以后卖掉。各弧费用与成本成正比。
AC代码:
#include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<vector> #include<cstdlib> #include<queue> #include<algorithm> using namespace std; #define LL long long #define ULL unsigned long long #define UINT unsigned int #define MAX_INT 0x7fffffff #define MAX_LL 0x7fffffffffffffff #define MAX(X,Y) ((X) > (Y) ? (X) : (Y)) #define MIN(X,Y) ((X) < (Y) ? (X) : (Y)) #define INF 1000000000 #define MAXN 222 #define MAXM 22222 int n, s, t; struct edge{ int u, v, cap, flow, cst, nxt; }e[MAXM]; int h[MAXN], cc; void add(int u, int v, int cap, int prc){ e[cc]=(edge){u, v, cap, 0, prc, h[u]}; h[u]=cc++; e[cc]=(edge){v, u, 0, 0, -prc, h[v]}; h[v]=cc++; } int d[MAXN], p[MAXN], a[MAXN]; bool inq[MAXN]; bool BellmanFord(LL &ans){ int i; a[s]=INF; queue<int> q; q.push(s); memset(inq, 0, sizeof(inq)); inq[s]=true; for(i=0; i<n; i++) d[i]=INF; d[s]=0; while(!q.empty()){ int u=q.front(); q.pop(); inq[u]=false; for(i=h[u]; i!=-1; i=e[i].nxt){ int v=e[i].v, cap=e[i].cap, flow=e[i].flow, cst=e[i].cst; if(d[v]>d[u]+cst && cap>flow){ d[v]=d[u]+cst; p[v]=i; a[v]=MIN(a[u], cap-flow); if(!inq[v]) q.push(v), inq[v]=true; } } } if(d[t]>0) return false; //不固定负费用流 ans+=(LL)a[t]*(LL)d[t]; for(int u=t; u!=s; u=e[p[u]].u){ e[p[u]].flow+=a[t]; e[p[u]^1].flow-=a[t]; } return true; } LL mcmf(){ LL cst=0; while(BellmanFord(cst)); return cst; } int main(){ // freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin); int month, T, store_cst; scanf(" %d", &T); for(int ks=1; ks<=T; ks++){ int i, j; scanf(" %d %d", &month, &store_cst); t=2*month+1; s=0; n=2*month+2; memset(h, -1, sizeof(h)); cc=0; for(i=1; i<=month; i++){ int man_cst, man_pdt, sel_prc, sel_pdt, exp_dat; scanf(" %d %d %d %d %d", &man_cst, &man_pdt, &sel_prc, &sel_pdt, &exp_dat); add(s, i, man_pdt, man_cst); add(month+i, t, sel_pdt, -sel_prc); for(j=0; j<=exp_dat; j++) if(i+j<=month) add(i, month+i+j, INF, store_cst*j); } printf("Case %d: %lld\n", ks, -mcmf()); } return 0; }
相关文章推荐
- UVA - 11613 Acme Corporation(任意流最小费用)
- UVA 11613 Acme Corporation(不固定流量的最小费用流)
- UVA 11613 Acme Corporation(不固定流量的最小费用流)
- 无向图的最小费用最大流问题 UVa 10594 - Data Flow
- 最小费用最大流问题----poj 2135
- poj 2135 Farm Tour (最小费用最大流模板)
- 最小费用最大流模板
- POJ 3921 - Destroying the bus stations 构图最小费用最大流..
- 最小费用最大流问题
- Ural-1076 Trash(最小费用最大流算法)
- 最小费用最大流问题
- HDU 6118 度度熊的交易计划(最小费用最大流模板)
- 最小费用最大流模板
- 2011东北地区赛F题(最小费用最大流经典)
- POJ2195 Going Home(最小费用最大流模板题)(附用数组建图和用链式前向星建图代码)
- 数学建模常用Matlab/Lingo/c代码总结系列——最小费用最大流问题
- 最小费用最大流模板
- uva 11613 Acme Corporation(费用流)
- 最小费用最大流问题
- (最小费用最大流模板)HDU 3488