记录编号 128 评测结果 AAAAAAAAAA
题目名称 [POI 1998] 潜水员的问题 最终得分 100
用户昵称 Gravatar梦里醉逍遥 是否通过 通过
代码语言 Pascal 运行时间 2.435 s
提交时间 2008-04-25 08:16:32 内存使用 0.28 MiB
显示代码纯文本
program ple;
const
  fi='ple.in';  fo='ple.out';
  maxt=158;  maxa=158;
type
  arr=array[0..200,0..200] of longint;
  bag=array[1..1000] of longint;
var
  fin,fout:text;
  n,t,a,min:longint;
  f:arr;  ti,ai,wi:bag;

  procedure init;
  var
    i:longint;
  begin
    assign(fin,fi);  reset(fin);
    readln(fin,t,a);  readln(fin,n);
    for i:=1 to n do
      readln(fin,ti[i],ai[i],wi[i]);
    close(fin);
  end;

  procedure main;
  var
    i,j,k:longint;
  begin
    min:=maxlongint;
    for i:=1 to n do
      for j:=maxt downto ti[i] do
        for k:=maxa downto ai[i] do
          if ((j-ti[i]=0) and (k-ai[i]=0)) or (f[j-ti[i],k-ai[i]]<>0) then
          if (f[j,k]=0) or (f[j,k]>f[j-ti[i],k-ai[i]]+wi[i]) then
            f[j,k]:=f[j-ti[i],k-ai[i]]+wi[i];
    for j:=t to maxt do
      for k:=a to maxa do
        if (f[j,k]<min) and (f[j,k]<>0) then
          min:=f[j,k];
  end;

  procedure print;
  begin
    assign(fout,fo);  rewrite(fout);
    writeln(fout,min);  close(fout);
  end;

begin
  init;
  main;
  print;
end.