记录编号 39408 评测结果 AAAAAAAAAA
题目名称 [HNOI 1999] 快餐问题 最终得分 100
用户昵称 Gravatarfuhao 是否通过 通过
代码语言 Pascal 运行时间 1.321 s
提交时间 2012-07-10 13:26:55 内存使用 0.75 MiB
显示代码纯文本
program meal;
const maxn=11;
var
 a,b,c,p1,p2,p3,ans,n,i,j,x,y,nx,ny,many,r,cuple,l,numa,numb,numc:longint;
 f:array[0..maxn,0..100,0..100] of longint;
 sum,t:array[0..maxn] of longint;
 ok:array[0..maxn,0..100,0..100] of boolean;
 function min(x,y:longint):longint;
 begin
  if x>y then exit(y) else exit(x);
 end;
begin
 assign(input,'meal.in'); reset(input);
 assign(output,'meal.out'); rewrite(output);
 readln(a,b,c);
 readln(p1,p2,p3);
 readln(n);
 for i:=1 to n do read(t[i]);
 ans:=0; cuple:=a*p1+b*p2+c*p3;
 numa:=0; numb:=0; numc:=0;
 for i:=1 to n do
  begin
   while t[i]>=cuple do
    begin
      if numa+a>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
      if numb+b>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
      if numc+c>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
     numa:=numa+a; numb:=numb+b; numc:=numc+c;
     ans:=ans+1; t[i]:=t[i]-cuple;
    end;
   sum[i]:=sum[i-1]+t[i];
  end;
 ok[0,0,0]:=true;
 for i:=1 to n do
 begin
  for nx:=0 to min(100,sum[i-1] div p1) do
   for ny:=0 to min(100,sum[i-1] div p2) do
   begin
    if nx*p1+ny*p2>sum[i-1] then break;
    if ok[i-1,nx,ny] then
     for x:=0 to min(100,t[i] div p1) do
      begin
       l:=x+nx; if l>100 then break;
      for y:=0 to min(100,t[i] div p2) do
       begin
        r:=y+ny; if r>100 then break;
       if x*p1+y*p2<=t[i] then
       begin
        if f[i,l,r]<f[i-1,nx,ny]+(t[i]-x*p1-y*p2) div p3 then
         f[i,l,r]:=f[i-1,nx,ny]+(t[i]-x*p1-y*p2) div p3;
        ok[i,l,r]:=true;
        if ok[i,100,100] and (f[i,100,100] div c>=100 div a) then break;
       end else break;
       if ok[i,100,100] and (f[i,100,100] div c>=100 div a) then break;
       end;
       if ok[i,100,100] and (f[i,100,100] div c>=100 div a) then break;
      end;
   end;
  if ok[i,100,100] then
    if f[i,100,100] div c>=100 div a then
     begin
      f[n]:=f[i];
      ok[n]:=ok[i];
      break;
     end;
 end;
  many:=0;
  for i:=0 to 100 do
   for j:=0 to 100 do
    if ok[n,i,j] then
    begin
     ny:=maxlongint;
     x:=i div a; y:=j div b; nx:=f[n,i,j] div c;
     if ny>x then ny:=x;
     if ny>y then ny:=y;
     if ny>nx then ny:=nx;
     if many<ny then many:=ny;
    end;
  for i:=1 to many do
   begin
      if numa+a>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
      if numb+b>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
      if numc+c>100 then
       begin
        writeln(ans);
        close(input); close(output);
        halt;
       end;
     ans:=ans+1;
     numa:=numa+a; numb:=numb+b; numc:=numc+c;
   end;
  writeln(ans);
  close(input); close(output);
end.