[Network Stream 24 questions] Napkins

Source: Internet
Author: User

★ ¡ï Input File: napkin.in output file: napkin.out Simple comparison
Time limit: 1 s memory limit: MB

"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

Input file a total of 3 lines, the 1th Act of the Total Day teaching; 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 wash the required cost F, slow washing the number of 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

Exercises

The additional source s sinks T is created by dividing the vertex xi,yi into two points in two sets per day.
1, from S to each XI with a capacity of RI, the cost of 0 of the forward edge.
2, from each Yi to t even a capacity of RI, the cost of 0 of the forward edge.
3, from S to each yi a capacity for infinity, the cost of P of the forward edge.
4, from each XI to xi+1 (i+1<=n) a capacity of infinity, the cost of 0 of the forward edge.
5, from each XI to Yi+m (i+m<=n) a capacity of infinity, the cost of F of the forward edge.
6, from each XI to Yi+n (i+n<=n) a capacity of infinity, the cost of S has a forward edge.

After analysis can be used every day and run out of separation processing, modeling is a two-part diagram. The vertex XI in the binary graph x set represents the number of napkins used for the first day, the amount of which is RI, so the edge from S to Xi is connected to the side of the RI as a limitation. In the y set each point Yi is the day I need the napkin, the number is RI, with the T-connected edge capacity as the limit. Daily use of napkins can choose to stay to the next day (xi->xi+1), do not need to spend, sent to the fast-washing department (XI->YI+M), the cost of F, sent to the slow wash (xi->yi+n), the cost of S. The napkin that needs every day except freshly washed napkin, also may be new purchase (S->yi), the cost is P.

1#include <iostream>2#include <cstdio>3#include <cstdlib>4#include <cstring>5#include <cmath>6#include <algorithm>7#include <queue>8#include <vector>9 using namespacestd;Ten Const intinf=1e9; One Const intmaxn= +, maxm=2000000; A intn,r[maxn],p,k,a,m,b; - intS,t,maxflow,mincost; - structnode{ the     intTo,next,rest,cost; - }E[MAXM]; - intHead[maxn],cnt=1; -InlinevoidAddedge (intXintYintZintc) { +E[++cnt].to=y; E[cnt].rest=z; E[CNT].NEXT=HEAD[X]; head[x]=cnt; e[cnt].cost=C; -E[++cnt].to=x; e[cnt].rest=0; E[cnt].next=head[y]; head[y]=cnt; e[cnt].cost=-C; + } A intDIS[MAXN],PRE[MAXN]; at BOOLVIS[MAXN]; - BOOLSPFA () { -     Staticqueue<int>Q; -      for(inti=s;i<=t;i++) dis[i]=inf,vis[i]=false; -Q.push (S); dis[s]=0; vis[s]=true; -      while(!Q.empty ()) { in         intx=Q.front (); Q.pop (); -vis[x]=false; to          for(intI=head[x];i;i=E[i].next) { +             inty=e[i].to; -             if(e[i].rest&&dis[y]>dis[x]+e[i].cost) { thedis[y]=dis[x]+E[i].cost; *pre[y]=i; $                 if(vis[y]==false){Panax Notoginsengvis[y]=true; - Q.push (y); the                 } +             } A         } the     } +     returndis[t]<inf; - } $ voidUpdate () { $     intflow=inf; -      for(inti=pre[t];i;i=pre[e[i^1].to]) -flow=min (flow,e[i].rest); the      for(inti=pre[t];i;i=pre[e[i^1].to]) { -e[i].rest-=flow;Wuyie[i^1].rest+=flow; the     } -Maxflow+=flow; mincost+=flow*Dis[t]; Wu } - voidMCF () { Aboutmaxflow=mincost=0; $      while(SPFA ()) { - update ();  -     } - } A intMain () { + //freopen ("napkin.in", "R", stdin); the //freopen ("Napkin.out", "w", stdout); -scanf"%d",&N); $s=0; t=2*n+1; the  the      for(intI=1, r;i<=n;i++){ thescanf"%d",&R);  theAddedge (S,i,r,0); Addedge (N+i,t,r,0);  -     } inscanf"%d%d%d%d%d",&p,&k,&a,&m,&B); the      for(intI=1; i<=n;i++){ theAddedge (s,n+i,inf,p); About         if(i<n) Addedge (i,i+1Inf0); the         if(i+k<=n) Addedge (i,i+k+n,inf,a); the         if(i+m<=n) Addedge (i,i+m+n,inf,b); the     } + MCF (); -printf"%d", mincost); the     return 0;Bayi}

[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.