曹哲睿 2011-10-30 00:59:00
点我顶贴
收藏
删除
var
k,v,n,t,i,j,tt,w,ww,temp1,temp2:longint;
f:array[0..3,0..1100000] of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a) else exit(b);
end;
begin
read(n,v);
f[0,0]:=0;
for k:=1 to n do
begin
i:=(k-1)mod 3+1;
read(ww,tt,w,t);
for j:=v downto 0 do
begin
if j>=tt then
temp1:=max(f[i-1,j-tt]+ww,f[i-1,j]);
if j>=t then
temp2:=max(f[i-1,j-t]+w,f[i-1,j]);
f[i,j]:=max(temp1,temp2);
end;
end;
writeln(f[(n-1)mod 3 +1,v]);
end.