[HNOI2001] [BZOJ1221] Software development

Source: Internet
Author: User

1221: [HNOI2001] Software development time limit:10 Sec Memory limit:162 MB
submit:868 solved:482
[Submit] [Status] [Discuss] Description

A software company is planning an n-day software development program, according to the development plan I need NI software developers, in order to improve the efficiency of software developers, the company provides software personnel with a lot of services, one of the services is to provide each developer a daily disinfection towel, This disinfectant towel must be sterilized after one day to be used. Disinfection methods There are two, a mode of disinfection needs a day, B mode of disinfection needs B Day (B>a), a disinfection method of the cost of each towel FA, B disinfection method of the cost of each towel fb, and buy a new towel for the cost of f (new towel is disinfected, the day can be used); >FA>FB. The company's manager is planning how many new towels to buy each day, how many towels per day, and how many towels are sent per day for the B disinfection of these n days. Of course, company managers want the lowest cost. Your job is to plan how many towels to buy per day, how many towels per day, and how many towels to disinfect for B, so that the company has the lowest total cost of providing towel service in this N-day software development.

Input

1th Act N,A,B,F,FA,FB. 2nd Act N1,n2,......,nn. (Note: 1≤f,fa,fb≤60,1≤n≤1000)

Output

Minimum cost

Sample Input4 1 2 3 2 1
8 2 1 6
Sample Output38
HINT Source

Minimum cost maximum flow

First, ignoring the cost, the demand is that every day needs to meet. And every day towels have these sources: yesterday did not wash, bought a new, a day ago disinfection, B days ago disinfection. So tectonic dichotomy: the left side is today, and the right is needed today. And then even run the cost of the flow is good.
#include <iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#include<algorithm>#include<vector>#include<queue>#include<map>#include<Set>#defineINF 100000007#defineMAX 2000002#defineMAXN 2005#defineMOD 2002using namespacestd;intNext[max],list[max], from[Max],flow[max],cost[max];intHEAD[MAXN],DIS[MAXN],Q[MAXN],PATH[MAXN];intn,m,a,b,fa,fb,f,ans,cnt;BOOLV[MAXN];voidInsertintXintYintWintz) {next[++cnt]=Head[x]; HEAD[X]=CNT;  from[cnt]=x; LIST[CNT]=y; FLOW[CNT]=W; COST[CNT]=Z;}BOOLSPFA () {memset (V,0,sizeof(v));  for(intI=0; i<=2*n+1; i++) dis[i]=INF; dis[0]=1; v[0]=1; q[1]=0; intt=0, w=1, X;  while(t!=W) {T= (t+1)%MOD; X=Q[t];  for(intI=head[x];i;i=Next[i])if(flow[i]&&dis[x]+cost[i]<Dis[list[i]]) {Dis[list[i]]=dis[x]+Cost[i]; Path[list[i]]=i; if(!V[list[i]]) {V[list[i]]=1; W= (w+1)%MOD; Q[W]=List[i]; }} V[x]=0; }    returndis[2*n+1]!=INF;}voidmcf () {intx=Inf,i; I=path[2*n+1];  while(i) {x=min (x,flow[i]); I=path[ from[i]]; } I=path[2*n+1];  while(i) {ans+=cost[i]*x; Flow[i]-=x; Flow[i^1]+=x; I=path[ from[i]]; }}intMain () {scanf ("%d%d%d%d%d%d",&n,&a,&b,&f,&fa,&FB); CNT=1;  for(intI=1; i<=n;i++) {scanf ("%d",&m); Insert (0, I,m,0); Insert (I,0,0,0); Insert (i+n,2*n+1M0); Insert (2*n+1, I+n,0,0); Insert (0, n+i,inf,f); Insert (n+i,0,0,-f); }     for(intI=1; i<=n;i++)     {        if(i+1<=N) {insert (I,i+1Inf0); Insert (i+1I0,0); }        if(i+a+1<=N) {insert (I,n+i+a+1, INF,FA); Insert (n+i+a+1I0,-FA); }        if(i+b+1<=N) {insert (I,n+i+b+1, INF,FB); Insert (n+i+b+1I0,-FB); }} ans=0;  while(SPFA ()) MCF (); printf ("%d", ans); return 0;}

[HNOI2001] [BZOJ1221] Software development

Related Article

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.