第三个点过不去

P1417 烹调方案

kuonji @ 2017-03-15 22:31:17

第三个点过不去,

var
  t,n,i,j,k,t1,ans:longint;
  a,b,c:array[0..51] of longint;
  f:array[0..51,0..5000000] of longint;
function max(a,b:longint):longint;
begin
  if a>b then exit(a) else exit(b);
end;
begin
  read(t,n);
  for i:=1 to n do read(a[i]);
  for i:=1 to n do read(b[i]);
  for i:=1 to n do read(c[i]);
  for i:=1 to n do
    for j:=i+1 to n do
    begin
      if c[i]*b[j]<c[j]*b[i] then
      begin
        t1:=a[i]; a[i]:=a[j]; a[j]:=t1;
        t1:=b[i]; b[i]:=b[j]; b[j]:=t1;
        t1:=c[i]; c[i]:=c[j]; c[j]:=t1;
      end;
    end;
  for i:=1 to n do
    for j:=0 to t do
    begin
      if j-c[i]>=0 then
        f[i,j]:=max(f[i-1,j],f[i-1,j-c[i]]+a[i]-j*b[i])
      else f[i,j]:=f[i-1,j];
    end;
  for i:=0 to t do
    ans:=max(ans,f[n,i]);
  writeln(ans);
end.

by kuonji @ 2017-03-16 18:09:27

求大神帮忙


|