比赛 2008haoi模拟训练3 评测结果 WTWWTTTATA
题目名称 潜水员的问题 最终得分 20
用户昵称 cuixiaofei 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-04-24 11:20:25
显示代码纯文本
//na                            :cuixiaofei;
//da                            :08_04_24;
program ple;
  var
    y,d,n,min                   :longint;
    a                           :array[1..1000,1..3] of longint;
    pc                          :array[1..1000] of longint;
    f1,f2                       :text;
  procedure init;
    var
      i                         :longint;
  begin
    assign(f1,'ple.in');
    reset(f1);
    assign(f2,'ple.out');
    rewrite(f2);
    readln(f1,y,d);
    readln(f1,n);
    min:=maxlongint;
    for i:=1 to n do
      readln(f1,a[i,1],a[i,2],a[i,3]);
  end;
  procedure sou(y1,d1,z:longint);
    var
      i                         :longint;
  begin
    if z>min then
      exit
    else if (y1>y)and(d1>d)and(z<min) then
      min:=z
    else
      begin
        for i:=1 to n do
          if (pc[i]=0) and (z+a[i,3]<min) then
            begin
              pc[i]:=1;
              sou(y1+a[i,1],d1+a[i,2],z+a[i,3]);
              pc[i]:=0;
            end;
      end;
  end;
  begin
    init;
    fillchar(pc,sizeof(pc),0);
    sou(0,0,0);
    writeln(f2,min);
    close(f1);
    close(f2);
  end.