bzoj_1221_ [Hnoi2001]_ Software development (network flow 24, minimum cost flow)

Source: Internet
Author: User

Describe

http://www.lydsy.com/JudgeOnline/problem.php?id=1221

n days, need r a towel every day, after use can wash, either spend FA wash a day, or spend FB wash B days, towel enough can say f buy one, ask at least how much money.

Analysis

Break each day into two points: X[i] for the first day of the Dirty Towel, y[i] for the first day to use the towel.

1.s to X[i] arc, capacity of r[i], the cost is 0, the daily use of dirty r[i] bar towel.

2.x[i] to x[i+1] arc (note the boundary), the capacity of the INF, the cost is 0, the first day of the dirty towel on the i+1 day (because may be put on hold for several days, so may not only r[i]).

3.x[i] to y[i+a+1] arc (note the border), the capacity of the INF, the cost of FA, the first day of the dirty towel taken to carry out a wash.

4.x[i] to x[i+b+1] arc (note the border), the capacity of the INF, the cost of FB, ibid.

5.S to Y[i] arc, the capacity of the INF (can actually be r[i], because y only flow to T, Max Stream r[i]), the cost of F, indicating the new buy towels.

6.y[i] to the T arc, the capacity of r[i], the cost is 0, the first day I used r[i] a towel.

Attention:

1. When using the ^ operation (0,1) is a group, (2,3) is a group like this, so from the even start, and can not start from 0, so starting from 2. (Debug for a long time ...)

P.S.

1. The first handwriting queue, no problem, did not expect to be handwritten list wrong ....

2. Network flow 24 Questions? Try it every day.

1#include <bits/stdc++.h>2 using namespacestd;3 4 Const intmaxn= ++5, inf=1<< -;5 intCnt=1;6 inthead[maxn<<1],q[maxn<<1],d[maxn<<1],p[maxn<<1];7 BOOLvis[maxn<<1];8 9 structedge{Ten     int  from, To,cap,cost,next; One Edge () {} AEdgeint  from,intTo,intCapintCostintNext): from( from), to, Cap (CAP), cost, next (next) {} -}g[maxn*MAXN]; - voidAdd_edge (intUintVintCapintCost ) { theG[++cnt]=edge (U,v,cap,cost,head[u]); head[u]=CNT; -G[++cnt]=edge (V,u,0,-cost,head[v]); head[v]=CNT; - } - BOOLSPFA (intSintt) { +      for(inti=s;i<=t;i++) D[i]=inf, vis[i]=false; -d[s]=0; vis[s]=true; +     intFront=0, tail=0; Aq[tail++]=s; at      while(front!=tail) { -         intU=q[front++];if(front==2001) front=0; -vis[u]=false; -          for(intI=head[u];i;i=g[i].next)if(g[i].cap&&d[g[i].to]>d[u]+g[i].cost) { -d[g[i].to]=d[u]+G[i].cost; -p[g[i].to]=i; in             if(!Vis[g[i].to]) { -vis[g[i].to]=true; toq[tail++]=g[i].to;if(tail==2001) tail=0; +             } -         } the     } *     returnd[t]!=INF; $ }Panax Notoginseng intMin_cost (intSintt) { -     intret=0, F; the      while(SPFA (s,t)) { +f=INF; A          for(intU=t;u!=s;u=g[p[u]]. from) f=min (f,g[p[u]].cap); the          for(intU=t;u!=s;u=g[p[u]]. from) G[p[u]].cap-=f, g[p[u]^1].cap+=F; +ret+=d[t]*F; -     } $     returnret; $ } - intMain () { -     intN,A,B,F,FA,FB; thescanf"%d%d%d%d%d%d",&n,&a,&b,&f,&fa,&FB); -     ints=0, t= (n<<1)+1;Wuyi      for(intI=1; i<=n;i++){ the         if(i+1<=n) Add_edge (i,i+1Inf0); -         if(i+a+1<=n) Add_edge (i,n+i+a+1, INF,FA); Wu         if(i+b+1<=n) Add_edge (i,n+i+b+1, INF,FB); -Add_edge (0, n+i,inf,f); About     } $      for(intI=1; i<=n;i++){ -         intR scanf"%d",&R); -Add_edge (S,i,r,0); -Add_edge (N+i,t,r,0); A     } +printf"%d\n", Min_cost (s,t)); the     return 0; -}
View Code

1221: [HNOI2001] Software development time limit:10 Sec Memory limit:162 MB
submit:1236 solved:685
[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
Hintsource

bzoj_1221_ [Hnoi2001]_ Software development (network flow 24, minimum cost flow)

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.