记录编号 14720 评测结果 AWWWWAAAAAA
题目名称 [USACO Oct09] Bessie 的体重问题 最终得分 63
用户昵称 Gravatarmaxiem 是否通过 未通过
代码语言 Pascal 运行时间 0.016 s
提交时间 2009-11-03 17:08:18 内存使用 0.19 MiB
显示代码纯文本
program diet;
var
  j,i,ans,tmp,h,n:longint;
  f:array [1..500] of boolean;
  s:array [1..500] of longint;
procedure dfs(sum:longint);
var i:integer;
begin
  if sum>ans then ans:=sum;
  for i:=1 to n do if (not(f[i])) and (sum+s[i]<=h) then begin
    f[i]:=true;
    dfs(sum+s[i]);
  end;
end;
begin
  ans:=0;
  fillchar (f,sizeof(f),0);
  fillchar (s,sizeof(s),0);
  assign (input,'diet.in');
  reset (input);
  readln (h,n);
  for i:=1 to n do readln (s[i]);
  for i:=1 to n-1 do begin
    for j:=i+1 to n do if s[i]<s[j] then begin
      tmp:=s[i];
      s[i]:=s[j];
      s[j]:=tmp;
    end;
  end;
  close (input);
  assign (output,'diet.out');
  rewrite (output);
  dfs(0);
  writeln (ans);
  close (output);
end.