BZOJ2424: [HAOI2010]訂貨

來源:互聯網
上載者:User

標籤:des   style   blog   http   color   os   io   strong   

2424: [HAOI2010]訂貨Time Limit: 10 Sec  Memory Limit: 128 MB
Submit: 420  Solved: 275
[Submit][Status]Description

某公司估計市場在第i個月對某產品的需求量為Ui,已知在第i月該產品的訂貨單價為di,上個月月底未銷完的單位產品要付存貯費用m,假定第一月月初的庫存量為零,第n月月底的庫存量也為零,問如何安排這n個月訂購計劃,才能使成本最低?每月月初訂購,訂購後產品立即到貨,進庫並供應市場,於當月被售掉則不必付存貯費。假設倉庫容量為S。

  

 

Input

第1行:n, m, S (0<=n<=50, 0<=m<=10, 0<=S<=10000)

第2行:U1 , U2 , ... , Ui , ... , Un (0<=Ui<=10000)

第3行:d1 , d2 , ..., di , ... , dn (0<=di<=100)

 

Output

只有1行,一個整數,代表最低成本

 

Sample Input3 1 1000
2 4 8
1 2 4
Sample Output34HINT Source

Day1

題解:這題算是比較裸的費用流了需要注意的一點就是i 向 i+n 連邊的容量應該是倉庫容量+該天的需求量代碼:
  1 const inf=maxlongint;  2 type node=record  3      from,go,next,v,c:longint;  4      end;  5 var e:array[0..2000000] of node;  6     pre,head,q,d:array[0..1000000] of longint;  7     v:array[0..1000000] of boolean;  8     i,j,n,m,maxf,s,t,l,r,mincost,tot,x:longint;  9 function min(x,y:longint):longint; 10  begin 11  if x<y then exit(x) else exit(y); 12  end; 13 procedure ins(x,y,z,w:longint); 14  begin 15  inc(tot); 16  with e[tot] do 17   begin 18   from:=x;go:=y;v:=z;c:=w;next:=head[x];head[x]:=tot; 19   end; 20  end; 21 procedure insert(x,y,z,w:longint); 22  begin 23  ins(x,y,z,w);ins(y,x,0,-w); 24  end; 25 function spfa:boolean; 26  var i,x,y:longint; 27  begin 28  fillchar(v,sizeof(v),false); 29  for i:=s to t do d[i]:=inf; 30  l:=0;r:=1;q[1]:=s;d[s]:=0;v[s]:=true; 31  while l<r do 32   begin 33   inc(l); 34   x:=q[l];v[x]:=false; 35   i:=head[x]; 36   while i<>0 do 37    begin 38    y:=e[i].go; 39    if (e[i].v<>0) and (d[x]+e[i].c<d[y]) then 40     begin 41     d[y]:=d[x]+e[i].c; 42     pre[y]:=i; 43     if not(v[y]) then 44      begin 45      v[y]:=true; 46      inc(r); 47      q[r]:=y; 48      end; 49     end; 50    i:=e[i].next; 51   end; 52  end; 53  exit(d[t]<>inf); 54  end; 55 procedure mcf; 56  var i,tmp:longint; 57  begin 58  mincost:=0; 59  while spfa do 60   begin 61   tmp:=inf; 62   i:=pre[t]; 63   while i<>0 do 64    begin 65    tmp:=min(tmp,e[i].v); 66    i:=pre[e[i].from]; 67    end; 68   inc(mincost,tmp*d[t]); 69   i:=pre[t]; 70   while i<>0 do 71    begin 72    dec(e[i].v,tmp); 73    inc(e[i xor 1].v,tmp); 74    i:=pre[e[i].from]; 75    end; 76   end; 77  end; 78 procedure init; 79  begin 80  tot:=1; 81  readln(n,m,maxf); 82  s:=0;t:=2*n+1; 83  for i:=1 to n do 84   begin 85   read(x); 86   insert(i+n,t,x,0); 87   insert(i,i+n,maxf+x,0); 88   end; 89  for i:=1 to n do 90   begin 91   read(x); 92   insert(s,i,inf,x); 93   end; 94  for i:=1 to n-1 do insert(i+n,i+1,inf,m); 95  end; 96 procedure main; 97  begin 98  mincost:=0; 99  mcf;100  writeln(mincost);101  end;102 begin103  assign(input,‘input.txt‘);assign(output,‘output.txt‘);104  reset(input);rewrite(output);105  init;106  main;107  close(input);close(output);108 end.  
View Code

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.