比赛 暑假培训五 评测结果 AAAAWWWWTA
题目名称 开心的金明 最终得分 50
用户昵称 苏轼 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-07-22 10:21:08
显示代码纯文本
program happy;

var th:array[0..25]of integer;
    p:array[0..25]of integer;
    gh:array[0..25,0..10000]of longint;
    n,m:word;

function max(a,b:longint):longint;
 begin
  if a>b then max:=a else max:=b;
 end;

procedure input;
 var f:text;
     i:integer;
 begin
  assign(f,'happy.in');
  reset(f);
  readln(f,n,m);
  for i:=1 to m do
   readln(f,p[i],th[i]);
  close(f);
 end;

procedure output;
 var f:text;
 begin
  assign(f,'happy.out');
  rewrite(f);
  writeln(f,gh[m,n]);
  close(f);
 end;

procedure main;
 var i,j:word;
 begin
  for i:=1 to n do
    gh[1,i]:=0;

  for i:=p[1] to n do
   gh[1,i]:=th[1]*p[1];

  for i:=2 to m do
   for j:=1 to n do
    if p[i]<=j then
     gh[i,j]:=max(gh[i-1,j],gh[i-1,j-p[i]]+p[i]*th[i]) else
     gh[i,j]:=gh[i-1,j];
 end;

begin
 input;
 main;
 output;
end.