某公司估计市场在第i个月对某产品的需求量为Ui,已知在第i月该产品的订货单价为di,上个月月底未销完的单位产品要付存贮费用m,假定第一月月初的库存量为零,第n月月底的库存量也为零,问如何安排这n个月订购计划,才能使成本最低?每月月初订购,订购后产品立即到货,进库并供应市场,于当月被售掉则不必付存贮费。假设仓库容量为S。
标签:min cal cte else res eof close strong page
只有1行,一个整数,代表最低成本
1 /************************************************************** 2 Problem: 2424 3 User: 1090900715 4 Language: Pascal 5 Result: Accepted 6 Time:96 ms 7 Memory:344 kb 8 ****************************************************************/ 9 10 program j01; 11 var f:array[0..10000]of longint; 12 g:array[0..20000]of longint; 13 u,d:array[0..50]of longint; 14 n,m,s,i,j,x:longint; 15 function min(a,b:longint):longint; 16 begin 17 if a<b then exit(a) else exit(b); 18 end; 19 begin 20 readln(n,m,s); 21 for i:=1 to n do read(u[i]); 22 for i:=1 to n do read(d[i]); 23 fillchar(f,sizeof(f),$3f); 24 f[0]:=0; 25 for i:=1 to n do 26 begin 27 for j:=0 to s do f[j]:=f[j]+j*m-d[i]*j; 28 x:=maxlongint; 29 for j:=0 to s do 30 begin 31 x:=min(x,f[j]); 32 g[j]:=x+d[i]*j; 33 end; 34 for j:=s+1 to s+u[i] do g[j]:=x+d[i]*j; 35 for j:=0 to s do f[j]:=g[j+u[i]]; 36 end; 37 writeln(f[0]); 38 end.
标签:min cal cte else res eof close strong page
原文地址:http://www.cnblogs.com/oldjang/p/6129231.html