COGS461. [Network Stream 24 questions] Napkins

Source: Internet
Author: User

"Problem description"

A restaurant in successive N days, the first day I need RI block napkins (i=l,2,...,n). The restaurant can get napkins from three different ways.

(1) Buy a new napkin, each piece needs p points;

(2) Send the used napkin to the quick wash, wash a piece of M days, the cost of f (f<p). such as M=l, the first day to the fast-washing department of the napkin can be used the next day, send slow washing is also the case.

(3) The napkin is sent to the slow wash, wash a piece of n Days (n>m), the cost of S (s<f).

At the end of each day, the restaurant must decide how many pieces of used napkins are delivered to the fast-washing section, and how many blocks are delivered to the slow wash. At the beginning of each day, the restaurant must decide whether to buy new napkins and how much, so that the washing and the new purchase of napkins and meet the demand for the day RI, and the total cost of n days is the smallest.

Input

The input file total 3 lines, the 1th Act total number of days, the 2nd act the number of napkin blocks required per day; 3rd Act the new purchase fee for each napkin: p, fast wash the required number of days m, fast washing required f, slow washing required days n, slow washing cost s.

Output

One line, the minimum cost

"Examples"

Napkin.in

3
3 2 4
10 1 6) 2 3

Napkin.out

64

"Data Size"

N<=200,ri<=50

Although it is finished, it is not very well explained.

Go out the left turn hzwer god Ben Blog

1#include <iostream>2#include <stdio.h>3#include <stdlib.h>4#include <string.h>5#include <algorithm>6#include <queue>7 #defineLL Long Long8 using namespacestd;9 Const intinf=1e9;Ten Const intmxn= About*2; OneInlineintRead () { A     intsum=0, flag=1;CharCh=GetChar (); -      while(ch!='-'&& (ch>'9'|| ch<'0')) ch=GetChar (); -     if(ch=='-') {flag=-1; ch=GetChar ();} the      while(ch<='9'&&ch>='0') {sum=sum*Ten+ch-'0'; ch=GetChar ();} -     returnsum*Flag; - } - structedge{ +     intu,v,nxt,f,w; -}e[mxn*mxn*2]; + inthd[mxn],mct=1; A voidAdd_edge (intUintVintCintW) { atE[++MCT].U=U;E[MCT].V=V;E[MCT].NXT=HD[U];E[MCT].F=C;E[MCT].W=W;HD[U]=MCT;return; - } - voidInsertintUintVintCintW) { -Add_edge (u,v,c,w); Add_edge (V,u,0,-W);return; - } - intn,p,n,m,s,t; in inta,f,s; - intDIS[MXN]; to intPRE[MXN]; + BOOLINQ[MXN]; - BOOLSPFA () { thememset (DIS,0x3f,sizeofdis); *queue<int>Q; $ Q.push (S);Panax Notoginsengdis[s]=0; -      while(!Q.empty ()) { the         intU=q.front (); Q.pop (); inq[u]=0; +          for(intI=hd[u];i;i=e[i].nxt) { A             intv=e[i].v; the             if(e[i].f>0&& dis[v]>dis[u]+E[I].W) { +dis[v]=dis[u]+E[I].W; -pre[v]=i; $                 if(!Inq[v]) { $inq[v]=1; - Q.push (v); -                 } the             } -         }Wuyi     } the     if(dis[t]!=0x3f3f3f3f)return 1; -     return 0; Wu } - intsolve () { About     inttmp=0x3f3f3f3f, res=0; $      while(SPFA ()) { -tmp=0x3f3f3f3f; -          for(intI=pre[t];i>1; i=PRE[E[I].U]) { -tmp=min (tmp,e[i].f); A         } +          for(intI=pre[t];i>1; i=PRE[E[I].U]) { thee[i].f-=tmp; -e[i^1].f+=tmp; $res+=tmp*E[I].W; the         } the     } the     returnRes; the } - intMain () { inFreopen ("napkin.in","R", stdin); theFreopen ("Napkin.out","W", stdout); the     inti,j; Aboutn=read (); thes=0; t=n*2+1; the      for(i=1; i<=n;i++){ theA=read (); +Insert (S,i,a,0); -Insert (I+n,t,a,0); the     }BayiP=read (); M=read (); F=read (); N=read (); s=read (); the      for(i=1; i<=n;i++){ the         if(i+1<=n) Insert (i,i+1Inf0); -         if(i+m<=n) Insert (i,i+m+n,inf,f); -         if(i+n<=n) Insert (i,i+n+n,inf,s); theInsert (S,I+N,INF,P);//buy the     } the     intans=solve (); theprintf"%d\n", ans); -     return 0; the}

COGS461. [Network Stream 24 questions] Napkins

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.