比赛 NOIP2008集训模拟4 评测结果 AWWWWWWWWW
题目名称 灵魂分流药剂 最终得分 10
用户昵称 cuixiaofei 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-11-13 10:50:18
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_11_13;
program soultap;
  type
    sss                         =record
                            zhi :longint;
                            ji  :array[1..10] of longint;
                                end;
    s                           =record
                         nei,yi,xi,ku:longint
                                end;
  var
    n,m,a,b                     :longint;
    f                           :array[0..110,0..110,0..110] of sss;
    du                          :array[1..100] of s;
    f1,f2                       :text;
  procedure init;
    var
      i                         :longint;
  begin
    assign(f1,'soultap.in');
    reset(f1);
    assign(f2,'soultap.out');
    rewrite(f2);
    readln(f1,n,m,a,b);
    fillchar(f,sizeof(f),0);
    for i:=1 to n do
      readln(f1,du[i].nei,du[i].yi,du[i].xi,du[i].ku);
  end;
  procedure dp;
    var
      i,j,k,max                 :longint;
  begin
    for i:=1 to n do
      for j:=1 to a do
        if j-du[i].nei>=0 then
        for k:=1 to b do
          if k-du[i].yi>=0 then
          begin
            max:=0;
            if (f[i-1,j-du[i].nei,k-du[i].yi].ji[du[i].xi]=0) then
              begin
                if (f[i-1,j-du[i].nei,k-du[i].yi].zhi+du[i].ku>f[i-1,j,k].zhi) then
                  begin
                    f[i,j,k].zhi:=f[i-1,j-du[i].nei,k-du[i].yi].zhi+du[i].ku;
                    f[i,j,k].ji:=f[i-1,j-du[i].nei,k-du[i].yi].ji;
                    f[i,j,k].ji[du[i].xi]:=1;
                  end
                else
                  begin
                    f[i,j,k].zhi:=f[i-1,j,k].zhi;
                    f[i,j,k].ji:=f[i-1,j,k].ji;
                  end;
              end;
          end;
  end;
  procedure print;
    var
      i,j,max                   :longint;
  begin
    max:=-100000;
    for i:=1 to a do
      for j:=1 to b do
        if f[n,i,j].zhi>max then
          max:=f[n,i,j].zhi;
    writeln(f2,max);
    close(f1);
    close(f2);
  end;
  begin
    init;
    dp;
    print;
  end.