比赛 NOIP2008集训模拟4 评测结果 AAAWAAWAAA
题目名称 灵魂分流药剂 最终得分 80
用户昵称 MayLava 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 11:09:59
显示代码纯文本
program MayLava;

type
 rec=record
  pa,pb,w:longint;
 end;

var
 pack:array[0..11,0..101]of rec;
 num:array[0..11]of longint;
 scv:array[0..101,0..101]of longint;
 n,m,a,b:longint;

procedure start;
 var
  f:text;
  i,x1,x2,x3,x4:longint;
 begin
  fillchar(pack,sizeof(pack),0);
  fillchar(scv,sizeof(scv),0);
  fillchar(num,sizeof(num),0);
  assign(f,'soultap.in');
  reset(f);
  readln(f,n,m,a,b);
  for i:=1 to n do begin
   readln(f,x1,x2,x3,x4);
   inc(num[x3]);
   with pack[x3,num[x3]] do begin
    pa:=x1;
    pb:=x2;
    w:=x4;
   end;
  end;
  close(f);
 end;

function max(a,b:longint):longint;
 var
  m:longint;
 begin
  m:=0;
  if a>m then m:=a;
  if b>m then m:=b;
  exit(m);
 end;

procedure main;
 var
  i,j1,j2,k:longint;
 begin
  for k:=1 to m do
   for j1:=a downto 0 do
    for j2:=b downto 0 do
     for i:=1 to num[k] do
      if (j1-pack[k,i].pa>0) and (j2-pack[k,i].pb>0) then
       scv[j1,j2]:=max(scv[j1,j2],scv[j1-pack[k,i].pa,j2-pack[k,i].pb]+pack[k,i].w);
 end;

procedure print;
 var
  f:text;
  i,j,ma:longint;
 begin
  ma:=0;
  for i:=a downto 0 do
   for j:=b downto 0 do
    if scv[i,j]>ma then ma:=scv[i,j];
  assign(f,'soultap.out');
  rewrite(f);
  writeln(f,ma);
  close(f);
 end;

BEGIN
 start;
 main;
 print;
END.