1221: [hnoi2001] software development time limit: 10 sec memory limit: 162 MB
Submit: 503 solved: 265
[Submit] [Status] Description
A software company is planning a software development plan for N days. According to the development plan, ni software developers are required on day I. To improve the efficiency of software developers, the company has provided a lot of services to software personnel. One of the services is to provide each developer with a sterile towel every day, which can only be used after being disinfected for one day. There are two disinfection methods: Method A and method B (B> ), the cost of a disinfection method is Fa for each towel, and the cost of B disinfection method is fb for each towel, and the cost of buying a new towel is F (the new towel is disinfected, can be used on the current day), and F> fa> FB. The company manager is planning how many new towels are bought each day during the N days, how many towels are sent each day for a type of disinfection, and how many towels are sent each day for B type of disinfection. Of course, the company manager wants the lowest cost. Your task is to plan how many towels to buy for the software company, how many towels to disinfect a and how many towels to disinfect a day, this minimizes the total cost of providing towel services during the n-day software development.
Input
1st behavior n, A, B, F, fa, FB. 2nd behavior N1, N2 ,......, Nn. (Note: 1 ≤ F, fa, FB ≤ 60, 1 ≤ n ≤ 1000)
Output
Minimum fee
Sample input4 1 2 3 2 1
8 2 1 6
Sample output 38
Hint Source
Maximum Flow with minimum cost
Question: Is this question different from the napkin plan ?... I did not say that I could leave it for the next day to wash my questions, causing my wa code:
1 const inf=maxlongint; 2 type node=record 3 from,go,next,v,c:longint; 4 end; 5 var e:array[0..2000000] of node; 6 pre,head,q,d:array[0..1000000] of longint; 7 v:array[0..1000000] of boolean; 8 i,j,n,m,maxf,s,t,l,r,mincost,tot,a,b,fa,fb,f,x:longint; 9 function min(x,y:longint):longint; 10 begin 11 if x<y then exit(x) else exit(y); 12 end; 13 procedure ins(x,y,z,w:longint); 14 begin 15 inc(tot); 16 with e[tot] do 17 begin 18 from:=x;go:=y;v:=z;c:=w;next:=head[x];head[x]:=tot; 19 end; 20 end; 21 procedure insert(x,y,z,w:longint); 22 begin 23 ins(x,y,z,w);ins(y,x,0,-w); 24 end; 25 function spfa:boolean; 26 var i,x,y:longint; 27 begin 28 fillchar(v,sizeof(v),false); 29 for i:=s to t do d[i]:=inf; 30 l:=0;r:=1;q[1]:=s;d[s]:=0;v[s]:=true; 31 while l<r do 32 begin 33 inc(l); 34 x:=q[l];v[x]:=false; 35 i:=head[x]; 36 while i<>0 do 37 begin 38 y:=e[i].go; 39 if (e[i].v<>0) and (d[x]+e[i].c<d[y]) then 40 begin 41 d[y]:=d[x]+e[i].c; 42 pre[y]:=i; 43 if not(v[y]) then 44 begin 45 v[y]:=true; 46 inc(r); 47 q[r]:=y; 48 end; 49 end; 50 i:=e[i].next; 51 end; 52 end; 53 exit(d[t]<>inf); 54 end; 55 procedure mcf; 56 var i,tmp:longint; 57 begin 58 mincost:=0; 59 while spfa do 60 begin 61 tmp:=inf; 62 i:=pre[t]; 63 while i<>0 do 64 begin 65 tmp:=min(tmp,e[i].v); 66 i:=pre[e[i].from]; 67 end; 68 inc(mincost,tmp*d[t]); 69 i:=pre[t]; 70 while i<>0 do 71 begin 72 dec(e[i].v,tmp); 73 inc(e[i xor 1].v,tmp); 74 i:=pre[e[i].from]; 75 end; 76 end; 77 end; 78 procedure init; 79 begin 80 tot:=1; 81 readln(n,a,b,f,fa,fb); 82 s:=0;t:=2*n+1; 83 for i:=1 to n do 84 begin 85 read(x); 86 insert(i+n,t,x,0); 87 insert(s,i,x,0); 88 insert(s,i+n,x,f); 89 if i+1<=n then insert(i,i+1,inf,0); 90 if i+a+1<=n then insert(i,i+a+n+1,inf,fa); 91 if i+b+1<=n then insert(i,i+b+n+1,inf,fb); 92 end; 93 94 end; 95 procedure main; 96 begin 97 mincost:=0; 98 mcf; 99 writeln(mincost);100 end;101 begin102 assign(input,‘input.txt‘);assign(output,‘output.txt‘);103 reset(input);rewrite(output);104 init;105 main;106 close(input);close(output);107 end.
View code