Napkins (COGS 461)

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 (Rokua n<=2000,ri<=10000000)

/*put on the valley will tle, the data is too big, COGS can, big data available network flow, Konjac Konjac do not understand.    Can see is greedy, but greedy strategy is not easy to think of.    If you consider the way of napkins, then we have to consider how much fast washing and slow washing, it is necessary to enumerate, not only trouble time complexity is also high, so should consider the source of napkins.  First of all, if you want to buy a certain number of napkins, should buy the sooner the better, because so far recycling can save money, but we do not know how many napkins, so to enumerate the number of napkins, in addition to buy napkins are not enough, you have to consider slow washing, and then consider fast washing. (if the napkin must be enough)*/#include<cstdio>#include<iostream>#include<cstring>#defineM 2010using namespacestd;intXu[m],q[m],n,p,t1,v1,t2,v2;intRead () {CharC=getchar ();intnum=0, flag=1;  while(c<'0'|| C>'9'){if(c=='-') flag=-1; c=GetChar ();}  while(c>='0'&&c<='9') {num=num*Ten+c-'0'; c=GetChar ();} returnnum*Flag;}intInitintsum) {    intans=0; memset (q,0,sizeof(q));  for(intI=1; i<=n;i++)    {        intx=Xu[i]; if(sum>=x) {ans+=x*p; Q[i]+=x; Sum-=x; X=0; }        Else if(sum>0) {ans+=sum*p; Q[i]+=sum; X-=sum; Sum=0; }        ////////////Slow Wash         for(intj=1; j<=i-t2;j++)          if(q[j]>0)          {              if(q[j]>=x) {ans+=x*v2; Q[J]-=x; Q[i]+=x; X=0;  Break; }              Else{ans+=q[j]*v2; Q[i]+=Q[j]; X-=Q[j]; Q[J]=0; }          }        ///////////fast-washing        if(!x)Continue;  for(intj=i-t1;j>=1; j--)//fast washing when the first choice of the back, was the pit for a long time!!!           if(q[j]>0)          {              if(q[j]>=x) {ans+=x*v1; Q[J]-=x; Q[i]+=x; X=0;  Break; }              Else{ans+=q[j]*v1; Q[i]+=Q[j]; X-=Q[j]; Q[J]=0; }          }        if(x>0)return 0; }    returnans;}intMain () {Freopen ("napkin.in","R", stdin); Freopen ("Napkin.out","W", stdout); intmaxn=0, sum=0; N=read ();  for(intI=1; i<=n;i++) Xu[i]=read (), Maxn=max (Maxn,xu[i]), sum+=Xu[i]; P=read (); T1=read (); V1=read (); T2=read (); v2=read (); intans=sum*p;  for(inti=sum-1; i>=maxn;i--)    {        intp=init (i); if(p) ans=min (ans,p); } printf ("%d", ans); return 0;}
View Code

Napkins (COGS 461)

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.